Skip to content

Instantly share code, notes, and snippets.

@simonjefford
Created February 1, 2012 09:06
Show Gist options
  • Save simonjefford/1716056 to your computer and use it in GitHub Desktop.
Save simonjefford/1716056 to your computer and use it in GitHub Desktop.
Y U NO Lazy?
(defn seq-from-nodelist [nodelist]
(let [nodecount (.getLength nodelist)]
(for [i (range nodecount)]
(do
(println "node")
(.item nodelist i)))))
;; nodelist contains 5 nodes
(def nodes (seq-from-nodelist nodelist))
;; prints node 5 times
(first nodes)
;; where as...
(defn lazytest []
(for [x (iterate inc 0)]
(do
(println "double")
(* 2 x))))
(def doubles (lazytest))
;; prints "double" once
(first doubles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment