Skip to content

Instantly share code, notes, and snippets.

@nicokosi
Last active December 15, 2015 11:19
Show Gist options
  • Save nicokosi/5252531 to your computer and use it in GitHub Desktop.
Save nicokosi/5252531 to your computer and use it in GitHub Desktop.
(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