Created
September 27, 2018 13:31
-
-
Save bhugueney/9ea8c5722472220236db5fc664661239 to your computer and use it in GitHub Desktop.
Examples of lazy sequences in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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