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
+4.7k Google : Block or disable caching of your website content
+18.6k Golang : Padding data for encryption and un-padding data for decryption
+4.5k Golang : How to pass data between controllers with JSON Web Token
+17.7k Golang : Put UTF8 text on OpenCV video capture image frame
+5.3k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+7.6k Golang : Get today's weekday name and calculate target day distance example
+10.3k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+5.2k Javascript : How to loop over and parse JSON data?
+9k Golang : How to get username from email address
+6k Javascript : Generate random key with specific length
+7.8k Golang : Sort words with first uppercase letter
+4.9k Swift : Convert (cast) Float to Int or Int32 value