merge combines one or more maps by copying key-value pairs into the first map. When keys conflict, later values replace earlier ones; the first map determines the output type. section 11.3.3
Key behavior and edge cases:
- With no arguments or only nil arguments, returns nil; with one non-nil argument, returns that argument. section 11.3.3
- Accepts Clojure map types such as hash maps, sorted maps, array maps, records, and structs; native java.util.HashMap is excluded. section 11.3.3
- A sorted-map target requires incoming keys comparable with its existing keys; an array-map can promote to a hash-map as it grows. section 11.3.3
Resolve conflicts explicitly
(merge {:a 1 :b 2} {:b 9 :c 3}) ;; {:a 1, :b 9, :c 3} Use merge-with when conflicts need computation rather than replacement: (merge-with + {:a 1} {:a 10 :b 2}) ;; {:a 11, :b 2}
Listing 11.11. → Map merging, Map processing
(merge [& maps]) (merge-with [f & maps])
Browse the compact signatures for merge and merge-with. section 11.3.3




