10 Monads

This chapter covers

  • Understanding functors
  • Going one step further from transform with monads
  • Composing functions that return wrapper types
  • Handling asynchronous operations in FP style

The functional programming world isn’t big on design patterns, but common abstractions pop up everywhere. These abstractions allow you to handle different types of problems from significantly different domains in the same way.

In C++, we already have one abstraction like this: iterators. With ordinary arrays, we can use pointers to move around and access data. We can use the operators ++ and -- to go to the next and previous elements, respectively, and we can dereference them with the * operator. The problem is, this works only for arrays and structures ...

Get Functional Programming in C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.