user=> (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}])
#'user/m1
user=> (require 'clojure.set)
nil
user=> (doc clojure.set/index)
-------------------------
clojure.set/index
([xrel ks])
Returns a map of the distinct values of ks in the xrel mapped to a
set of the maps in xrel with the corresponding values of ks.
nil
user=> (clojure.set/index m1 [:a :b])
{{:b 4, :a 1} #{{:a 1, :c 3, :b 4}}, {:b 2, :a 1} #{{:a 1, :c 4, :b 2} {:a 1,
:c 3, :b 2}}}
not exactly what you asked for, but I imagine you can get what you need from
here.
Cheers, Jay
On Jan 31, 2012, at 7:41 PM, ron peterson wrote:
> hello,
>
> 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 it 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}]]
>
> Thanks. R.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en