-
Book Overview & Buying
-
Table Of Contents
Mastering JavaScript Functional Programming - Third Edition
By :
Back in Chapter 5, Programming Declaratively, and later, in Chapter 8, Connecting Functions, we saw that the ability to apply a mapping to all the elements of an array—and even better, being able to chain a sequence of similar operations—was an excellent 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) 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 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 will be limited because we can only apply that to basic JavaScript types) or wrap types in some type of container, which will allow mapping and...