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
+22k Golang : Match strings by wildcard patterns with filepath.Match() function
+18.3k Golang : How to get hour, minute, second from time?
+6.7k Golang : Join lines with certain suffix symbol example
+22.1k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+6k PHP : How to check if an array is empty ?
+8.8k Golang : Gaussian blur on image and camera video feed examples
+12k Golang : convert(cast) string to integer value
+10.7k PHP : Convert(cast) bigInt to string
+13.7k Golang : Check if an integer is negative or positive
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+14.4k Golang : Rename directory
+9.9k Golang : Check if user agent is a robot or crawler example