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
+10.6k Golang : convert(cast) float to string
+17.3k Golang : Example for RSA package functions
+8.7k PHP : Get coordinates latitude/longitude from string
+28.2k Golang : Get and Set User-Agent examples
+9.5k Golang : Roll the dice example
+5.7k Default cipher that OpenSSL used to encrypt a PEM file
+13.3k Golang : How to filter a map's elements for faster lookup
+13.1k Golang : GUI with Qt and OpenCV to capture image from camera
+4.8k nginx : force all pages to be SSL
+7.6k Golang : Sort lines of text example
+24.6k Golang : missing Mercurial command
+12.4k Golang : How to get year, month and day?