How to become lazy

As you may know, laziness is a simple concept. It is the act of only doing the minimum required, or to postpone work until the very last moment. This is a conscious choice, and therefore must be applied with care.

One of the reasons Clojure is enjoyable as a programming language is because it makes it easy to be lazy; or, in simple computing terms, it only evaluates the minimum needed, when it is needed. Nothing extra.

So, why would you want to be lazy, or in other words, build lazy sequences? Obviously, to avoid unnecessary computations. An example of this is, say, if you have a mathematical formula or a repeating function defining a list of elements and you only want to use some of those elements. This is when you want to write ...

Get Clojure Programming Cookbook 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.