Building containers 

Back in Chapter 5, Programming Declaratively  A Better Style, and later, in Chapter 8, Connecting Functions – Pipelining and Composition, we saw that the ability to be able to apply a mapping to all the elements of an array—and, even better, being able to chain a sequence of similar operations—was a good way to produce better, more understandable code.

However, there is a problem: the map() method (or the equivalent, demethodized one, which we looked at in Chapter 6, Producing Functions  Higher-Order Functions), is only available for arrays, and we might want to be able to apply mappings and chaining to other data types. So, what can we do?

Let's consider different ways of doing this, which will give us several new ...

Get Mastering JavaScript Functional Programming - Second Edition now with O’Reilly online learning.

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