April 2012
Intermediate to advanced
296 pages
7h 3m
English
Most Clojure sequences are lazy; in other words, elements are not calculated until they are needed. Using lazy sequences has many benefits:
Consider the code and following expression:
| src/examples/primes.clj | |
(ns examples.primes) | |
;; Taken from clojure.contrib.lazy-seqs | |
; primes cannot be written efficiently as a function, because | |
; it needs to look back on the whole sequence. contrast with | |
; fibs and powers-of-2 which only need a fixed buffer of 1 or 2 | |
; previous values. | |
(def primes | |
(concat | |
[2 3 5 7] | |
(lazy-seq ... | |
Read now
Unlock full access