I am trying idiomatically merge multiple maps into a single map using clojure.
Input
{:a 1 :b "a"}
{:a 2 :b "b"}
{:a 3 :b "c"}
{:a 4 :b "a"}
Expected
{:a #{1,2,3,4}, :b #{"a" "b" "c"}}
The values for each key are converted into a set of values in the original maps.
I’d use
merge-with, using a pre-built structure that contains empty sets:The trick of using empty sets in the base map is so that
conjhas a concrete object to work upon, and hence works correctly.