Skip to content

Instantly share code, notes, and snippets.

@gjohnson
Created August 26, 2014 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjohnson/14d23b3f9cd8cdda6c23 to your computer and use it in GitHub Desktop.
Save gjohnson/14d23b3f9cd8cdda6c23 to your computer and use it in GitHub Desktop.
Ghetto idea of optional callbacks
package main
import "fmt"
import "reflect"
func main() {
fn1 := createCallback()
fn1()
fn2 := createCallback(func() {
fmt.Println("sweet")
})
fn2()
}
func createCallback(args ...interface{}) func() {
return func() {
if 0 == len(args) {
return
}
v := reflect.ValueOf(args[0])
v.Call([]reflect.Value{})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment