Implementing collections via closures
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.
Getting ready
Refer to the steps given in the Getting ready section of the Converting Data Types and Interface Casting recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create and navigate to the
chapter3/collectionsdirectory. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter3/collections or use this as an exercise to write some of your own code...