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
+18.9k Golang : Calculate entire request body length during run time
+5.5k Golang : Error handling methods
+5.6k Golang : Launching your executable inside a console under Linux
+9.9k Golang : Check a web page existence with HEAD request example
+8.8k Golang : Capture text return from exec function example
+8.5k Golang : Executing and evaluating nested loop in html template
+13.6k Golang : Human readable time elapsed format such as 5 days ago
+16.9k Golang : How to tell if a file is compressed either gzip or zip ?
+15.9k Golang : How to check if input from os.Args is integer?
+11.9k Golang : md5 hash of a string
+11k Use systeminfo to find out installed Windows Hotfix(s) or updates
+3.9k Javascript : Empty an array example