Golang: Function Return Function
To have a function return a function, the tricky part is in the return type spec.
func f(args) returnType {body}
The returnType must be a function type, like this:
func (args) returnType2
The whole thing looks like this:
func f(args) func (args) returnType2 {body}
package main import "fmt" // ff returns a function gg func ff(x int) func(int) int { var gg = func(y int) int { return y + x } return gg } func main() { fmt.Println(ff(1)(2)) // 3 }