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
+6.8k Golang Hello World Example
+20.5k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+18.2k Golang : Check if os.Stdin input data is piped or from terminal
+11.1k Golang : How to check if a string starts or ends with certain characters or words?
+5.1k Linux/Unix : Commands that you need to be careful about
+27.9k Golang : missing Git command
+12.8k Golang : syscall.Socket example
+8.3k Golang : Convert(cast) string to int64
+8.5k Golang : Resumable upload to Google Drive(RESTful) example
+9.3k Golang : How to delete element(data) from map ?
+7.9k Golang : Generate random Chinese, Japanese, Korean and other runes