Golang : On lambda, anonymous, inline functions and function literals
Tags : golang lambda anonymous inline-function 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:
Tags : golang lambda anonymous inline-function function-literals
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
+3.2k Golang : Validate IPv6 example
+10.8k Golang : Save map/struct to JSON or XML file
+8.5k Golang : convert(cast) string to float value
+2.4k Golang : Load DSA public key from file example
+3k Golang : Allow Cross-Origin Resource Sharing request
+5.3k Golang : syscall.Socket example
+10.1k Golang :Trim white spaces from a string
+3.5k Golang : Accessing content anonymously with Tor
+3.2k Golang : Find and draw contours with OpenCV example
+13.4k Golang : Use wildcard patterns with filepath.Glob() example
+1.3k Golang : Find the longest line of text example