November 2017
Intermediate to advanced
670 pages
17h 35m
English
See that {ret = n + 2} is our anonymous function/function literal/closure/lambda expression.
Our function literal:
package mainfunc curryAddTwo(n int) (ret int) { defer func(){ret = n + 2}() return n}func main() { println(curryAddTwo(1))}
The output is as follows:
3
Note that we used the defer statement to delay the execution of our function literal until after its surrounding function (curryAddTwo) is returned. Since our anonymous function has access to all the variables in its scope (n), it can modify n. The modified ...