Yes, just change the grouping function passed to group-by: (group-by #(vector (% "Type") (% "Subtype")) coll)
The keys in the resulting map will be two-element vectors (e.g. ["TypeA" "SubTypeA"]) so you'll need to adjust the body of the for a bit in BG's example. Cheers, Dave On Sun, Oct 16, 2011 at 5:55 AM, der <derealme.derea...@gmail.com> wrote: > Thanks BG and all other responses for your help. > > I have a followup question, could the same approach be extended if I > wanted to group-by multiple entries in the map? e.g. assuming the map > now had Type and Subtype and I wanted to "group-by" the pair Type and > Subtype, would the same approach work? > > On Oct 14, 9:45 pm, Baishampayan Ghose <b.gh...@gmail.com> wrote: >> > I'm a Clojure newbie trying to the following simple task: >> >> >Givenalistofmapsof the followign format: ({"Type" "A", "Value" >> > "5"} {"Type" "B", "Value" "4"} {"Type" "A", "Value" "7.2"} {"Type" >> > "A", "Value" "25.4"} {"Type" "B", "Value" "2.982"}) >> >> > I want to compute alistofmapssuch that each type appears once in >> > thelistand the value of the type is the sum of the values, so that >> > in the example it would be: >> >> > ({"Type", "A", "Value", "37.6"} {"Type", "B", "Value", "6.982"}) >> >> > Any ideas? >> >> I might write it like this - >> >> (defn sum-by-type [coll] >> (for [[k v] (group-by #(% "Type") coll)] >> {"Type" k "Value" (apply + (map (comp #(Float/parseFloat %) >> #(% "Value")) v))})) >> >> Regards, >> BG >> >> -- >> Baishampayan Ghose >> b.ghose at gmail.com > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en