On Thursday, April 14, 2011 8:51:47 PM UTC-4, Andreas Kostler wrote:
>
> (reduce + (map :b p))
; Or, save one character:
(apply + (map :b p))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.
> user=> (->> p (map :b) (reduce +))
Alternatively:
user> (def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6}))
#'user/p
user> (:b (apply merge-with + p))
9
Depending on whether you'll want the other sums or not, this approach
might be appropriate.
U
--
You received this message bec
For some people this might read better also :
user=> (->> p (map :b) (reduce +))
9
2011/4/15 Andreas Kostler :
> Or: (reduce #(+ %1 (:b %2)) 0 p)
>
> :)
> On Apr 15, 10:51 am, Andreas Kostler geosystems.com> wrote:
>> (reduce + (map :b p))
>> Cheers
>> Andreas
>>
>> On 15 April 2011 10:43, Bhin
Or: (reduce #(+ %1 (:b %2)) 0 p)
:)
On Apr 15, 10:51 am, Andreas Kostler wrote:
> (reduce + (map :b p))
> Cheers
> Andreas
>
> On 15 April 2011 10:43, Bhinderwala, Shoeb
> wrote:
>
>
>
>
>
>
>
>
>
> > I am a beginner in Clojure.
>
> > I have a list of maps:
>
> > (def p '({:a 1 :b 2 :c 4}, {:a
(reduce + (map :b p))
Cheers
Andreas
On 15 April 2011 10:43, Bhinderwala, Shoeb wrote:
> I am a beginner in Clojure.
>
> I have a list of maps:
>
> (def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6}))
>
> How do I add up all the :b values in the map? Result should be 9 (=2+3+4)
>
> I
I am a beginner in Clojure.
I have a list of maps:
(def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6}))
How do I add up all the :b values in the map? Result should be 9
(=2+3+4)
I know I should be using one of the higher level functions like apply,
reduce and combine it with a custom