Chapter 6Repeating with Recursion
Using map, reduce, and keep takes care of most of your needs when you process lists and arrays. There are some drawbacks, though. The functions process every element in the collection, and sometimes they don’t quite fit as a solution to the problem, so the higher-order function you provide is difficult to express.
Recursion is the answer to these annoying issues. It lets you process only part of a collection and can also let you express your algorithm more cleanly.
Recursion has a bad reputation for being arcane or confusing. It does take a bit of getting used to, but it’s one of those things that—once you start using it—you’ll wonder how you ever got along without it. In fact, in this chapter, we’ll even ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access