Novice question, but I don’t really understand why there are so many operations for constructing maps in clojure.
You have conj, assoc and merge, but they seem to more or less do the same thing?
(assoc {:a 1 :b 2} :c 3)
(conj {:a 1 :b 2} {:c 3})
(merge {:a 1 :b 2} {:c 3})
What’s really the difference and why are all these methods required when they do more or less the same thing?
assocandconjbehave very differently for other data structures:If you are writing a function that can handle multiple kinds of collections, then your choice will make a big difference.
Treat
mergeas a maps-only function (its similar toconjfor other collections).My opinion: