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 : Use TLS version 1.2 and enforce server security configuration over client
+31.2k Golang : Calculate percentage change of two values
+13.3k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+16.5k Golang : Check if a string contains multiple sub-strings in []string?
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+16.5k Golang : Get IP addresses of a domain name
+9.4k Golang : How to get username from email address
+9.4k Golang : Timeout example
+7.3k Golang : File system scanning
+20.4k Swift : Convert (cast) Int to int32 or Uint32
+8.8k Golang : Gorilla web tool kit schema example
+21.2k Golang : Get password from console input without echo or masked