Go is a statically typed language, and this means that a given channel can only send or receive data of a single data type. In Go's terminology, this is known as a channel's element type. A Go channel will accept any valid Go data type including functions. Here is an example of a simple program that accepts and calls on functions:
// elems.go
package main
import "fmt"
func main() {
// Let's create three simple functions that take an int argument
fcn1 := func(i int) {
fmt.Println("fcn1", i)
}
fcn2 := func(i int) {
fmt.Println("fcn2", i*2)
}
fcn3 := func(i int) {
fmt.Println("fcn3", i*3)
}
ch := make(chan func(int)) // Channel that sends & receives functions that take an int argument
done := make(chan bool) ...