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
+19.8k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+16.3k Golang : How to implement two-factor authentication?
+11.6k Golang : convert(cast) float to string
+10.9k Golang : Fix go.exe is not compatible with the version of Windows you're running
+18.3k Golang : Logging with logrus
+17.9k Golang : Convert IPv4 address to decimal number(base 10) or integer
+16.7k Golang : Get own process identifier
+7.3k Golang : Create zip/ePub file without compression(use Store algorithm)
+22.4k Generate checksum for a file in Go
+18.1k Golang : Get path name to current directory or folder
+10.3k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+6.2k WARNING: UNPROTECTED PRIVATE KEY FILE! error message