diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-08-20 12:48:24 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-08-20 12:48:24 -0400 |
commit | f1f5ad40984d46bdc314090552b76471ee2b8d01 (patch) | |
tree | 85af458fa38e67053e0c60c6d425543155653c62 /src | |
parent | 1abb7a56de1678321054af7fce183184f06974dd (diff) | |
parent | 5cddaf84b648657237bc1b5d81d65a5072e9c3be (diff) |
Merge branch 'lazychain'
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/core.clj | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index f7f4ee99..aaf5eda4 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -2610,10 +2610,18 @@ (cons (first s) (take-nth n (drop n s)))))) (defn interleave - "Returns a lazy seq of the first item in each coll, then the second - etc." - [& colls] - (apply concat (apply map list colls))) + "Returns a lazy seq of the first item in each coll, then the second etc." + ([c1 c2] + (lazy-seq + (let [s1 (seq c1) s2 (seq c2)] + (when (and s1 s2) + (cons (first s1) (cons (first s2) + (interleave (rest s1) (rest s2)))))))) + ([c1 c2 & colls] + (lazy-seq + (let [ss (map seq (conj colls c2 c1))] + (when (every? identity ss) + (concat (map first ss) (apply interleave (map rest ss)))))))) (defn var-get "Gets the value in the var object" |