Laziness in Practice

To really get our arms around lazy sequences, let’s try a more interesting example. Suppose we needed some more or less randomly generated book maps for testing. We could sit down and manually cook up some nonsense books like this:

 (​def​ test-books
  [{:author ​"Bob Jordan"​, :title ​"Wheel of Time, Book 1"​}
  {:author ​"Jane Austen"​, :title ​"Wheel of Time, Book 2"​}
  {:author ​"Chuck Dickens"​, :title ​"Wheel of Time, Book 3"​}
  {:author ​"Leo Tolstoy"​, :title ​"Wheel of Time, Book 4"​}
  {:author ​"Bob Poe"​, :title ​"Wheel of Time, Book 5"​}
  {:author ​"Jane Jordan"​, :title ​"Wheel of Time, Book 6"​}
  {:author ​"Chuck Austen"​, :title ​"Wheel of Time, Book 7"​}])

This will work, but armed with lazy sequences ...

Get Getting Clojure 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.