O'Reilly logo

Mastering JavaScript Functional Programming by Federico Kereki

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required