11 Higher Kinded Types and Beyond
In this chapter
- Applying map() to various other types
- Encapsulating error propagation
- Monads and their applications
- Resources for further study
Throughout the book we looked at various versions of a very common algorithm, map(), and in chapter 10 we saw how iterators provide an abstraction that allows us to reuse it across various data structures. In this chapter we’ll see how we can extend this beyond iterators and provide an even more general version. This powerful algorithm allows us to mix-and-match generic types and functions and can help by providing a uniform way to handle errors.
After we go over a few examples, we’ll provide a definition for this broadly applicable family of functions, known as functors. We’ll also explain what higher kinded types are and how they help us define such generic functions. We’ll look at the limitations we run into with languages which lack support for higher kinded types.
Next, we’ll look at monads. The term shows up in multiple places, and while it might sound intimidating, the concept is straight-forward. We’ll explain what a monad is, and go over multiple applications, from better error propagation to asynchronous code and sequence flattening.