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
+24.6k Mac/Linux and Golang : Fix bind: address already in use error
+7.9k Golang : automatically figure out array length(size) with three dots
+4k HTTP common errors and their meaning explained
+5.2k Golang : How to solve "too many .rsrc sections" error?
+12.7k Golang : How to convert a number to words
+5.4k Grep : How to grep for strings inside binary data
+4.5k Golang : Shortening import identifier
+5.2k Golang : Create new color from command line parameters
+7.3k Golang : How to check if input string is a word?
+18.9k Nginx + FastCGI + Go Setup.
+13.8k Golang : How to check for empty array string or string?
+14.2k Golang : Delete certain files in a directory