Last active
December 15, 2015 11:19
-
-
Save nicokosi/5252531 to your computer and use it in GitHub Desktop.
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
(defn lazy-inc [x] | |
(lazy-seq | |
(print ".") | |
(cons x (lazy-inc (inc x))))) | |
(print "\n take 2: ") | |
(take 2 | |
(lazy-inc 1)) | |
(print "\n first: ") | |
(first | |
(lazy-inc 1)) | |
(print "\n 2 first odds: ") | |
(take 2 | |
(filter odd? (lazy-inc 1))) | |
(print "\n first > 3: ") | |
(first | |
(drop-while #(>= 3 %) (lazy-inc 1))) | |
(print "\n 2 first odds > 3: ") | |
(take 2 | |
(filter odd? | |
(drop-while #(>= 3 %) (lazy-inc 1)))) | |
(defn lazy-pairs [x] | |
(lazy-seq (print ".") | |
(cons [x x] (lazy-pairs (inc x))))) | |
(print "\n 2 first lazy pairs which sum > 3: ") | |
(take 2 | |
(drop-while #(> 10 (reduce + %)) (lazy-pairs 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment