Chapter 12, Building Better Containers – Functional Data Types

12.1. Maybe tasks? The following code shows a simpler solution than the one we looked at in question 8.2:

const pending = Maybe.of(listOfTasks)  .map(getField("byPerson"))  .map(filter(t => t.responsible === name))  .map(t => tasks)  .map(t => t[0])  .map(filter(t => !t.done))  .map(getField("id"))  .valueOf();

Here, we apply one function after the other, secure in the knowledge that if any of these functions produces an empty result (or even if the original listOfTasks is null), the sequence of calls will go on. In the end, you will either get an array of task IDs or a null value.

12.2. Extending your trees: Calculating the tree's height is simple if you do this in a recursive fashion. ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.