assoc
and conj
behave very differently for other data structures:
user=> (assoc [1 2 3 4] 1 5)
[1 5 3 4]
user=> (conj [1 2 3 4] 1 5)
[1 2 3 4 1 5]
If you are writing a function that can handle multiple kinds of collections, then your choice will make a big difference.
Treat merge
as a maps-only function (its similar to conj
for other collections).
My opinion:
- assoc – use when you are ‘changing’ existing key/value pairs
- conj – use when you are ‘adding’ new key/value pairs
- merge – use when you are combining two or more maps