Created
January 10, 2017 01:23
-
-
Save guesslin/58e304e7ec73929c34aa920f0b186a6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type NameFn func() string | |
func delegate(name string) func() string { | |
return func() string { | |
return name | |
} | |
} | |
func main() { | |
names := []string{"guesslin", "mephisto"} | |
var namesFn []NameFn | |
for _, name := range names { | |
namesFn = append(namesFn, delegate(name)) | |
} | |
for _, fn := range namesFn { | |
fmt.Println(fn()) | |
fmt.Printf("%##v\n", fn) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment