Skip to content

Instantly share code, notes, and snippets.

@jmgimeno
Created April 18, 2012 06:56
Show Gist options
  • Save jmgimeno/2411576 to your computer and use it in GitHub Desktop.
Save jmgimeno/2411576 to your computer and use it in GitHub Desktop.
Does not hold the head of a sequance only its first element and the generating function.
(defn crazy-seq [head f]
(reify
clojure.lang.ISeq
(first [_] head)
(more [_] (crazy-seq (f head) f))
(next [this] (rest this))
(seq [this] this)
(equiv [_ _] false)))
(def s (crazy-seq 0 inc)) ; hold head
(dorun (take 100000000 s)) ; low fat
(nth s 10) ; recomputes
;=> 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment