diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-02-02 22:55:05 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-02-02 22:55:05 +0000 |
commit | 4bd4f231e1c5a822b918a5c80a640aa98b0f48ff (patch) | |
tree | 61e0382f3a04d38bdc7d39ba1a36862b6cde63ab | |
parent | 47304c217fb1140e4b3766222c314651f311e9e2 (diff) |
[lazy] moved filter, drop, drop-while to loop idiom
-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 5c4263f6..217010db 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1442,12 +1442,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] - (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)))) + (lazy-seq + (loop [coll coll] + (when (seq coll) + (if (pred (first coll)) + (cons (first coll) (filter pred (more coll))) + (recur (more coll))))))) (defn remove @@ -1475,11 +1475,11 @@ (defn drop "Returns a lazy sequence of all but the first n items in coll." [n coll] - (let [step (fn [n coll] - (if (and (pos? n) (seq coll)) - (recur (dec n) (more coll)) - (seq coll)))] - (lazy-seq (step n coll)))) + (lazy-seq + (loop [n n coll coll] + (if (and (pos? n) (seq coll)) + (recur (dec n) (more coll)) + coll)))) (defn drop-last "Return a lazy sequence of all but the last n (default 1) items in coll" @@ -1490,11 +1490,11 @@ "Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns nil." [pred coll] - (let [step (fn [pred coll] - (if (and (seq coll) (pred (first coll))) - (recur pred (more coll)) - (seq coll)))] - (lazy-seq (step pred coll)))) + (lazy-seq + (loop [coll coll] + (if (and (seq coll) (pred (first coll))) + (recur (more coll)) + coll)))) (defn cycle "Returns a lazy (infinite!) sequence of repetitions of the items in coll." |