Chapter 3. Few data structures, many operations
This chapter covers
- Understanding program control and flow
- Reasoning efficiently about code and data
- Unlocking the power of map, reduce, and filter
- Discovering the Lodash.js library and function chains
- Thinking recursively
Computational processes are abstract beings that inhabit computers. As they evolve, processes manipulate other abstract things called data.
Harold Abelson and Gerald Jay Sussman (Structure and Interpretation of Computer Programs, MIT Press, 1979)
Part 1 of this book accomplished two important goals: on one hand, those chapters got your feet wet by teaching you how to think functionally and introducing the tools you’ll need to use functional programming. Second, you took a condensed tour of many core JavaScript features, particularly higher-order functions, that will be used frequently throughout this chapter and the rest of the book. Now that you know how to make functions pure, it’s time to learn how to connect them.
In this chapter, I’ll introduce you to a few useful and practical operations like map, reduce, and filter that allow you to traverse and transform data structures in a sequential manner. These operations are so important that virtually all functional programs use them in one way or another. They also facilitate removing manual loops from your code, because most loops are just specific cases handled by these functions.