1
1
mirror of https://github.com/namibia/awesome-cheatsheets.git synced 2024-11-22 12:55:21 +00:00

fix: add anon funcs in go cheatsheet

This commit is contained in:
LuanSilveiraSouza 2021-03-09 15:56:15 -03:00
parent 61f5d0359f
commit 9b89b3136a

View File

@ -416,7 +416,7 @@ switchValuesAndDouble(2, 5)
// b = 4 // b = 4
// aux = 0 // 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 { func calc(fn func(int, int) int) int {
return fn(2, 6) return fn(2, 6)
} }
@ -431,6 +431,11 @@ func mult(x, y int) int {
calc(sum) // 8 calc(sum) // 8
calc(mult) // 12 calc(mult) // 12
calc(
func(x, y int) int {
return x / y
}
) // 3
// Function closures: a function that returns a function // Function closures: a function that returns a function
// that remembers the original context // that remembers the original context