开发者

Why does concat on vectors evaluate to a list?

开发者 https://www.devze.com 2022-12-28 07:37 出处:网络
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?

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 开发者_JAVA百科2 3 4 5 6)
; Why not: [1 2 3 4 5 6] ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消