January 2014
Intermediate to advanced
232 pages
5h 11m
English
Many Clojure algorithms use lazy evaluation. This means the operations aren’t performed unless somebody actually asks for their result. This is crucial to making many algorithms work efficiently.
For example, you might think the preceding example is very inefficient since we have to iterate our sequence each time to create the range, map across it, interpose, and reduce the result.
However, this is not actually the case. The evaluation of each expression happens on demand. The first value in range is generated and passed to the rest of the functions, then the next, and so on, until the sequence is exhausted. This is similar to the way iterators work in languages like Python.
Read now
Unlock full access