Q:

Anonymous Functions in Golang

I'm new to the go language and functional programming. 
My question is:  but can you enumerate the benefits of anonymous functions in golang. I understand from this site that anonymous functions are "segments code which will only need to get run once and doesn’t need to be referenced." but I can't find the benefit from them.

A:

A function literal represents an anonymous function. The specification mentions the primary benefit of function literals:

Function literals are closures: they may refer to variables defined in a surrounding function. Those variables are then shared between the surrounding function and the function literal, and they survive as long as they are accessible.

Here are some examples uses of anonymous functions: sort.Slice, http mux.HandleFunc, panic recovery, goroutines, filepath.Walk, ast.Inspect.

