Map

Section • 1 episode • 31 min

The map operation is the simplest of the trio, allowing us to simply transform the underlying type contained in some generic context. However, don’t let its simplicity fool you. There is a very powerful idea to be explored in the signature of the map function.

Related content

We encountered the map operation when exploring composable parsing. We were naturally led to this operation when we saw that it would be useful to be able to transform a parser’s value without needing to actually run the parser.

Composable Parsing: Map
23 min

Not only can map be defined on types that represent parsing, but it can even be defined on types representing randomness! In this episode we showed that an entire library of randomness generators could be built out of a single random integer generator.

Composable Randomness
40 min

In this episode we introduce the idea of contravariance and show that it can be viewed through a functional lens by taking the signature of the map operation and giving it a little flip!

Contravariance
38 min

Where to go from here

Now that you understand the basics of the map operation and how it can be applied to real world library design, it’s time to explore the zip operation. This operation allows you to do things that map alone is not capable of.