diff options
author | Sam Zaydel <szaydel@gmail.com> | 2014-07-09 20:56:01 -0700 |
---|---|---|
committer | Sam Zaydel <szaydel@gmail.com> | 2014-07-09 20:56:01 -0700 |
commit | 55e1c2adafcf0f2590633064aaf83af5ff1964af (patch) | |
tree | 484c1bb3416642248cc038d5fb508a2310e7db31 | |
parent | 8b6920a70a6f52657bf59a20a4120af98e4187fe (diff) |
Go inline function literals as arguments to other functions or function literals.
-rw-r--r-- | go.html.markdown | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/go.html.markdown b/go.html.markdown index a9a7de72..e496117e 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -188,6 +188,15 @@ func learnFlowControl() { x = 1.3e3 // This makes x == 1300 fmt.Println("xBig:", xBig()) // false now. + // What's more is function literals may be defined and called inline, + // acting as an argument to function, as long as: + // a) function literal is called immediately (), + // b) result type matches expected type of argument. + fmt.Println("Add + double two numbers: ", + func(a, b int) int { + return (a + b) * 2 + }(10, 2)) // Called with args (10, 2) + // When you need it, you'll love it. goto love love: |