tags:

views:

106

answers:

1

Calling concat on vectors returns a list. Being a total noob I would expect that the result would also be a vector. Why the conversion to list?

Example:

user=> (concat [1 2] [3 4] [5 6])
(1 2 3 4 5 6)
; Why not: [1 2 3 4 5 6] ?
+8  A: 

concat returns a lazy sequence.

user=> (doc concat)
-------------------------
clojure.core/concat
([] [x] [x y] [x y & zs])
  Returns a lazy seq representing the concatenation of the elements in the supplied colls.

you can convert it back to a vector with into:

user=> (into [] (concat [1 2] [3 4] [5 6]))
[1 2 3 4 5 6]

into uses transients so it's pretty quick about it.

dnolen
There's also `vec` for slightly shorter code with very similar performance.
Michał Marczyk