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
+12k Golang : How to parse plain email text and process email header?
+7.8k Gogland : Where to put source code files in package directory for rookie
+11.1k How to test Facebook App on localhost ?
+25.7k Golang : convert rune to integer value
+12.8k Golang : zlib compress file example
+7.9k Golang : Example of how to detect which type of script a word belongs to
+9.9k Random number generation with crypto/rand in Go
+11k Android Studio : Checkbox for user to select options example
+24.1k Golang : Fix type interface{} has no field or no methods and type assertions example
+17.1k Golang : XML to JSON example
+10k Golang : ffmpeg with os/exec.Command() returns non-zero status
+11.3k Golang : Calculate Relative Strength Index(RSI) example