Skip to content

Instantly share code, notes, and snippets.

@monkrus
Created January 13, 2020 23:43
Show Gist options
  • Save monkrus/50734b56e6039aaf1a96a90967a91cb3 to your computer and use it in GitHub Desktop.
Save monkrus/50734b56e6039aaf1a96a90967a91cb3 to your computer and use it in GitHub Desktop.
Return function in Go
package main
import (
"fmt"
)
func main() {
x := bar()
fmt.Printf("%T\n", x)
/
i := x()
fmt.Println(i)
}
func bar() func() int {
return func() int {
return 451
}
}
// when we run "bar()",
// it gives us "funct()int",
// we assign it to"x"
// The type of "funct() int" is the type "func() int"
// When we execute it, it returns "451", which we assign to "i"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment