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
+50.2k Golang : Check if item is in slice/array
+6.1k Linux : How to fix Brother HL-1110 printing blank page problem
+9.2k Golang : Text file editor (accept input from screen and save to file)
+2.9k Java : Random alphabets, alpha-numeric or numbers only string generator
+11.3k Golang : Validate email address
+9.5k Golang : Select region of interest with mouse click and crop from image
+8k Golang : How to extract video or image files from html source code
+5.2k Golang : Get missing location after unmarshal binary and gob decode time.
+14.3k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+12.8k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+11.8k Golang : http.Get example
+9.2k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)