7. Recursion II: Lazy Sequences
Overview
In this chapter, as we continue our exploration of recursive techniques, we will focus on lazy evaluation. We will write functions that safely produce potentially infinite lazy sequences, use lazy evaluation to consume linear data, produce lazily evaluated tree structures from linear data, and write functions that consume tree structures.
By the end of this chapter, you will be able to think about new ways of understanding and solving problems.
Introduction
At its simplest, a lazy sequence is a hybrid of two things:
- A list (not a vector!) of zero or more items
- A reference to possible future items of the list that can be computed if necessary
In other words, there's a real part and a virtual part. ...
Get The Clojure Workshop 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.