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 : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+5.2k Golang : Detect face in uploaded photo like GPlus
+3.6k Javascript : Access JSON data example
+17.1k Golang : Logging with logrus
+6.3k Golang : Rot13 and Rot5 algorithms example
+21.2k Golang : Set and Get HTTP request headers example
+8.8k Golang : Test a slice of integers for odd and even numbers
+5.5k Unix/Linux : Use netstat to find out IP addresses served by your website server
+14.3k Golang : invalid character ',' looking for beginning of value
+26k Golang : Record voice(audio) from microphone to .WAV file
+9.8k Golang : Web routing/multiplex example