Anonymous function in GO language.

Takdirul Islam Sisir
2 min readNov 9, 2021

An anonymous function is a cute little relationship, which is complicated and doesn't have any name that has only love in arguments. You just want to hide it from anyone.

Okay, Let's come to the point. In Go language, we have the anonymous function. You will not normally do this, but you can use it if you want to check your code, routines, and launching goroutines.

Internal functions are anonymous functions, they don't have any function name and we also don't need to assign them to a variable, Just write and ROCK N ROLL.

Example :

package mainimport "fmt"
func main (){names:= []string{"Billu", "Killu", "Dillu"}for _,value := range names{// Declearing an anonymous functionfunc (arg string) {fmt.Println("Names are ", arg, " in anonymous function " )}(value)}}

Definition of Example:

We made a slice of names, then wrote a For loop to get values from the slice, inside For loop we have declared an anonymous function without any name just a parameter and we have passed the argument in parenthesis.

Let me know if there is any missing information or mistake, I just moved to Go from Python.

--

--