November 2017
Intermediate to advanced
386 pages
9h 22m
English
Back in the Parsing numbers section tacitly of Chapter 5, Programming Declaratively - A Better Style, we saw that using parseInt() with .reduce() would produce problems, because of the unexpected arity of that function, which took more than one argument:
["123.45", "-67.8", "90"].map(parseInt); // problem: parseInt isn't monadic!// [123, NaN, NaN]
We have more than one way to solve this. In the mentioned chapter, we went with an arrow function, that is a simple solution, with the added advantage of being clear to understand. In Chapter 7, Transforming Functions - Currying and Partial Application, we will see yet another, based on partial application. But, here, let's go with a higher-order function. What we need, is a function ...
Read now
Unlock full access