diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-02-03 13:37:04 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-02-03 13:37:04 +0000 |
commit | 096500d721751dff456f67c1a6b9f2c2caa66b5f (patch) | |
tree | af3769845848e399b9258b8e39f617d32cac92a8 | |
parent | 04c246d900827d8e74f93c0a9cf77fcc94cf76d9 (diff) |
[lazy] restore step fns in filter/drop
-rw-r--r-- | src/clj/clojure/core.clj | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index fcf08c5f..1b25eabc 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1447,12 +1447,12 @@ "Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects." [pred coll] - (lazy-seq - (loop [coll coll] - (when (seq coll) - (if (pred (first coll)) - (cons (first coll) (filter pred (more coll))) - (recur (more coll))))))) + (let [step (fn [pred coll] + (when (seq coll) + (if (pred (first coll)) + (clojure.lang.Cons. (first coll) (filter pred (more coll))) + (recur pred (more coll)))))] + (lazy-seq (step pred coll)))) (defn remove @@ -1480,11 +1480,11 @@ (defn drop "Returns a lazy sequence of all but the first n items in coll." [n coll] - (lazy-seq - (loop [n n coll coll] - (if (and (pos? n) (seq coll)) - (recur (dec n) (more coll)) - coll)))) + (let [step (fn [n coll] + (if (and (pos? n) (seq coll)) + (recur (dec n) (more coll)) + (seq coll)))] + (lazy-seq (step n coll)))) (defn drop-last "Return a lazy sequence of all but the last n (default 1) items in coll" @@ -1495,11 +1495,11 @@ "Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns nil." [pred coll] - (lazy-seq - (loop [coll coll] - (if (and (seq coll) (pred (first coll))) - (recur (more coll)) - coll)))) + (let [step (fn [pred coll] + (if (and (seq coll) (pred (first coll))) + (recur pred (more coll)) + (seq coll)))] + (lazy-seq (step pred coll)))) (defn cycle "Returns a lazy (infinite!) sequence of repetitions of the items in coll." |