Put an element to the tail of a collection

后端 未结 4 864
北海茫月
北海茫月 2021-02-02 05:25

I find myself doing a lot of:

(concat coll [e]) where coll is a collection and e a single element.

Is there a function for doing this in Clojure? I

4条回答
  •  爱一瞬间的悲伤
    2021-02-02 06:20

    concat does not add an element to the tail of a collection, nor does it concatenate two collections.

    concat returns a seq made of the concatenation of two other seqs. The original type of the collections from which seqs may be inferred are lost for the return type of concat.

    Now, clojure collections have different properties one must know about in order to write efficient code, that's why there isn't a universal function available in core to concatenate collections of any kind together. To the contrary, list and vectors do have "natural insertion positions" which conj knows, and does what is right for the kind of collection.

提交回复
热议问题