Can you explain this behaviour in Clojure ?
user=> (into [1 2 3] ["a" "b"])
[1 2 3 "a" "b"]
but
user=> (into '(1 2 3) ["a" "b"])
("b" "a" 1 2 3)
It is understandable that into with vector appends the items but why using into with list first reverts the items order and then prepends it to the list ?
into uses conj to add items into the source collection. conj appends items to the front for lists and to the end for vectors. Clojure lists are immutable singly-linked lists, so adding to the end of the list would be an O(n) operation. Insertion at the front is a constant-time operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With