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

Reply via email to