From 9b89b3136af895f18dec446ded5011c3de0f4fc4 Mon Sep 17 00:00:00 2001 From: LuanSilveiraSouza Date: Tue, 9 Mar 2021 15:56:15 -0300 Subject: [PATCH] fix: add anon funcs in go cheatsheet --- languages/golang.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/languages/golang.md b/languages/golang.md index 3ef0612..3bcd9ad 100644 --- a/languages/golang.md +++ b/languages/golang.md @@ -416,7 +416,7 @@ switchValuesAndDouble(2, 5) // b = 4 // aux = 0 -// Functions can be handled as values +// Functions can be handled as values and be anonymous functions func calc(fn func(int, int) int) int { return fn(2, 6) } @@ -431,6 +431,11 @@ func mult(x, y int) int { calc(sum) // 8 calc(mult) // 12 +calc( + func(x, y int) int { + return x / y + } +) // 3 // Function closures: a function that returns a function // that remembers the original context