Golang : On lambda, anonymous, inline functions and function literals
This is just a note for myself and maybe it can be useful to you too. In Golang, lambda, anonymous and inline functions are known as function literals. What it does is to allow you to create a short callback function but without creating a separate named function. In a nutshell, it allows you to specify the one-line function "in-line" a.k.a on the fly...
For example:
package main
import (
"fmt"
)
func main() {
add := func(a ,b int) int { return a + b }
fmt.Println(add(1,2))
}
This one-line function is rarely used, but can be useful in situations where you need to create a short callback function to evaluate various expressions quickly.
Hope this helps!
References:
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+25.9k Golang : missing Mercurial command
+12k Golang : Verify Linux user password again before executing a program example
+27.4k Golang : Find files by name - cross platform example
+15.1k Golang : Submit web forms without browser by http.PostForm example
+4.5k Golang : Valued expressions and functions example
+17.8k Golang : Upload/Receive file progress indicator
+15.8k Golang : Force download file example
+12.5k Golang : List running EC2 instances and descriptions
+11k PHP : Convert(cast) bigInt to string
+21.6k Golang : How to force compile or remove object files first before rebuild?
+13.8k Golang : Tutorial on loading GOB and PEM files