Created
January 13, 2020 23:43
-
-
Save monkrus/50734b56e6039aaf1a96a90967a91cb3 to your computer and use it in GitHub Desktop.
Return function in Go
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 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