5 Higher-kinded composition

This chapter covers

  • Transforming arrays and objects safely with map and flatMap
  • Composable design patterns with algebraic data types
  • Writing a Validation data type to remove complex branching logic
  • Chaining ADTs using the new bind operator (::)

The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.

—Edgar Dijkstra

In chapter 4, you learned how function composition leads to fluent, compact, and declarative code when you use compose to chain your function’s inputs and outputs as data passes through them. Composition has a lot of benefits because it uses JavaScript’s strongest feature, as I’ve said many times: higher-order functions. With functions, ...

Get The Joy of JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.