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
+37.7k Golang : How to read CSV file
+18.2k Golang : Delete item from slice based on index/key position
+7k Swift : Convert (cast) String to Float
+16.5k Golang : How to log each HTTP request to your web server?
+6k Golang : Squaring elements in array
+26.6k Golang : Change a file last modified date and time
+3.9k Golang : Calculate a pip value and distance to target profit example
+7.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+8.3k Golang : Find correlation coefficient example