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
+7k Golang : How to solve "too many .rsrc sections" error?
+5.9k Golang : List all packages and search for certain package
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+5.9k Unix/Linux : How to open tar.gz file ?
+29.6k Golang : Saving(serializing) and reading file with GOB
+10.2k Golang : How to get quoted string into another string?
+10.3k Golang : Convert file content to Hex
+11.1k Golang : Web routing/multiplex example
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+17k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+6.9k Mac OSX : Find large files by size