Back in Chapter 5, Programming Declaratively - A Better Style, and later in Chapter 8, Connecting Functions - Pipelining and Composition, we saw that the ability of being 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, as in Chapter 6, Producing Functions - Higher-Order Functions), is available only 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 tools for better functional coding. Basically, there are only two possible ways of solving this: we can either add new methods to existing types (though that...