If you've been working with functional or dynamic programming languages, you may feel that for loops and if statements produce verbose code. Functional constructs such as map and filter for processing lists can be useful and make code appear more readable. However, in Go, these types are not in the standard library and can be difficult to generalize without generics or very complex reflection and use of empty interfaces. This recipe will provide you with some basic examples of implementing collections using Go closures.
Implementing collections via closures
Getting ready
Refer to the steps given in the Getting ready section of the Converting Data Types and Interface Casting recipe.