Welcome! Please see the About page for a little more info on how this works.

0 votes
in Collections by
closed by

I was wondering why the merge function doesn't use transients and if there could be a better version of that.

Instead of this:
(defn merge [& maps] (when (some identity maps) (reduce #(conj (or %1 {}) %2) maps)))

we can use transducers to keep the code still easy to read and have better performance:
(defn merge [& maps] (when (some identity maps) (into {} cat maps)))

closed as a duplicate of: Enhance the performance of map merges
You could also do it some other way than with the general transducer `cat`, maybe for an extra bit of performance.
The same situation with not using transients can be seen in `clojure.set` functions and maybe a few other functions as well.
Maybe the conj operation on a map should change as well? For now I don't see using transients - why not?