Skip to content

Instantly share code, notes, and snippets.

@bhugueney
Created September 27, 2018 13:31
Show Gist options
  • Save bhugueney/9ea8c5722472220236db5fc664661239 to your computer and use it in GitHub Desktop.
Save bhugueney/9ea8c5722472220236db5fc664661239 to your computer and use it in GitHub Desktop.
Examples of lazy sequences in Clojure
(def fib-seq
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
(def primes (lazy-cat [2] (filter (fn[candidate]
(not-any? #(zero? (mod candidate %1))
(take-while (partial > (Math/sqrt candidate))
primes)))
(iterate (partial + 2) 3))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment