How to group a collection of maps by multiple keys?
For example:
(def m1 [{:a 1 :b 2 :c 3}
{:a 1 :b 2 :c 4}
{:a 1 :b 4 :c 3}
{:a 1 :b 4 :c 3}])
(group-by-x [:a :b] m1)
I’d like to return this:
[{:a 1 :b 2} [{:a 1 :b 2 :c 3}{:a 1 :b 2 :c 4}],
{:a 1 :b 4} [{:a 1 :b 4 :c 3}{:a 1 :b 4 :c 3}]]
This returns a map:
To get exactly the return value you specified, wrap it in
(vec (apply concat ...)):This is equivalent, but perhaps prettier: