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
+26.6k Golang : Change a file last modified date and time
+5.6k Golang : How to setup a disk space used monitoring service with Telegram bot
+14.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+31.6k Delete a directory in Go
+12.9k Golang : Convert IP version 6 address to integer or decimal number
+20.9k Golang : Read directory content with filepath.Walk()
+4.4k Golang : Generate Interleaved 2 inch by 5 inch barcode
+7.5k Golang : Progress bar with ∎ character
+9.9k Golang : Create S3 bucket with official aws-sdk-go package
+18.3k Golang : Determine if directory is empty with os.File.Readdir() function
+6.9k Golang : Load DSA public key from file example
+10.6k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example