Q:

How to merge list of maps in clojure

I am given a list maps:
({:a 1 :b ["red" "blue"]} {:a 2 :b ["green"]} {:a 1 :b ["yellow"]} {:a 2 :b ["orange"]})

and I need to combine them to ultimately look like this:
({:a 1 :b ["red" "blue" "yellow"]} {:a 2 :b ["green" "orange"]})

Where the maps are combined based off the value of the key "a".
So far, I have this
(->> (sort-by :a)
     (partition-by :a)
     (map (partial apply merge)))

But the merge will overwrite the vector in "b" with the last one giving me
({:a 1 :b ["yellow"]} {:a 2 :b ["orange"]}) 

A:

Instead of merge, use merge-with, i.e. 
(->> a (sort-by :a) 
       (partition-by :a) 
       (map (partial 
          apply 
          merge-with (fn [x y] (if (= x y) x (into x y))))))

Outputs 
({:a 1, :b ["red" "blue" "yellow"]} {:a 2, :b ["green" "orange"]})

