Functions as binary trees

Can we do something similar with functions? The answer is yes: we will represent a tree (or any other structure) with a function itself -- and mind: not with a data structure that is processed by a set of functions, and not either with an object with some methods, but by just a function. Furthermore, we will get a functional data structure, 100% immutable, which if updated produces a new copy of itself. And, we will do all this without using objects; rather, closures will provide the desired results.

How can this work? We shall be applying similar concepts as those we saw earlier in the chapter, so the function will act as a container, and it will produce, as its result, a mapping of its contained values. Let's walk ...

Get Mastering Javascript Functional Programming now with O’Reilly online learning.

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