-
Book Overview & Buying
-
Table Of Contents
Functional Programming in Go
By :
The next category of functions which we will look at is Map functions. These are functions that apply a transformation function to each element in a container, changing the element and possibly even the data type. This is one of the most powerful functions in a functional programmer’s toolbox, as this allows you to transform your data according to a given rule.
There are two main implementations that we will look at. The first implementation is the simple Map function, whereby an operation is performed on each element, but the data type remains the same before and after the transformation – for example, multiplying each element in a slice. This will change the content of the values, but not the type of the values. The other implementation of Map is one whereby the data types can change as well. This will be implemented as FMap, and this is what we introduced in the previous chapter when looking into Monads.