performanceclojureclojure-core

Difference in implementation between clojure.core conj and clojure.core.into


What is the difference in terms of efficiency and under-the-hood details

between (apply conj [0][1]) and (into [0][1])?

Using the time function it seems that apply conj is faster, but is there a price? and what is it?


Solution

  • The into function is generally preferable to apply conj in Clojure due to the following reasons:

    That being said, there may be specific cases where apply conj is more suitable, such as when you need to dynamically pass in collection elements as variadic arguments. However, for most general cases, the into function is the preferred way to concatenate or merge collections in Clojure.