user=> (concat [1 2] [3 4])
(1 2 3 4)
user=> (into [] (concat [1 2] [3 4]))
[1 2 3 4]
user=> (concat [:a :b] nil [1 [2 3] 4])
(:a :b 1 [2 3] 4)
=> (concat [1] [2] '(3 4) [5 6 7] #{9 10 8})
(1 2 3 4 5 6 7 8 9 10)
(defn concat
"Returns a lazy seq representing the concatenation of the elements in the supplied colls."
{:added "1.0"}
([] (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))))
Comments top
No comments for concat. Log in to add a comment.