Created
February 25, 2020 12:07
-
-
Save fdv/c8791b614edc0aa5211420520ceab179 to your computer and use it in GitHub Desktop.
Use case
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" | |
func printString(foo string) { | |
fmt.Println(foo) | |
} | |
func printLen(foo string) { | |
fmt.Println(len(foo)) | |
} | |
type foo struct { | |
Value string | |
Func interface{} | |
} | |
func main() { | |
var fools = []foo{ | |
foo{ | |
Value: "hello world", | |
Func: printString, | |
}, | |
foo{ | |
Value: "goodbye world", | |
Func: printLen, | |
}, | |
} | |
for i := range fools { | |
fools[i].Func.(func(foo string))(fools[i].Value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment