summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2014-07-10 23:42:41 -0500
committerLevi Bostian <levi.bostian@gmail.com>2014-07-10 23:42:41 -0500
commit36dae81010fab9f511cb709721c276ae0da3eadb (patch)
treea4e7f1d15773403d4e4f79217310c4fa68ddd2ea
parentcd99d24a0e1d58448014e979c1d5507838d63181 (diff)
parent7cddab2925260946c61eac60cc62764017a8e8af (diff)
Merge pull request #671 from szaydel/master
Function literals used inline in Go language
-rw-r--r--go.html.markdown10
1 files changed, 10 insertions, 0 deletions
diff --git a/go.html.markdown b/go.html.markdown
index 4ea6861b..0ecc6120 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -188,6 +188,16 @@ 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 and 2
+ // => Add + double two numbers: 24
+
// When you need it, you'll love it.
goto love
love: