call_interface_function.go 342 B

1234567891011121314151617181920212223
  1. package main
  2. import "fmt"
  3. type Any interface{}
  4. var MyToplevelFunc = func() {
  5. fmt.Println("In: MyToplevelFunc")
  6. }
  7. var MyMap = func(sequence, f Any) {
  8. for _, v := range sequence.([]Any) {
  9. fmt.Println(f.(func(Any) Any)(v))
  10. }
  11. }
  12. func main() {
  13. MyToplevelFunc()
  14. MyMap([]Any{1, 2, 3, 4}, func(val Any) Any {
  15. return 10 * val.(int)
  16. })
  17. }