function | since v0.0-927 | clojure.core/concat | Edit |
(concat)
(concat x)
(concat x y)
(concat x y & zs)
Returns a lazy sequence representing the concatenation of the elements in the supplied collections.
(concat (list 1 2 3) (list 4 5 6))
;;=> (1 2 3 4 5 6)
(concat [1 2 3] (list 4 5 6))
;; => (1 2 3 4 5 6)
(concat [1] [2] [3])
;; => (1 2 3)
Returns a lazy seq representing the concatenation of the elements in the supplied colls.
(defn concat
([] (lazy-seq nil))
([x] (lazy-seq x))
([x y]
(lazy-seq
(let [s (seq x)]
(if s
(if (chunked-seq? s)
(chunk-cons (chunk-first s) (concat (chunk-rest s) y))
(cons (first s) (concat (rest s) y)))
y))))
([x y & zs]
(let [cat (fn cat [xys zs]
(lazy-seq
(let [xys (seq xys)]
(if xys
(if (chunked-seq? xys)
(chunk-cons (chunk-first xys)
(cat (chunk-rest xys) zs))
(cons (first xys) (cat (rest xys) zs)))
(when zs
(cat (first zs) (next zs)))))))]
(cat (concat x y) zs))))