(def foo {:a 5 :b 7})
(merge-with #(%2 %1) foo {:a inc :b #(+ 5 %)})
;; should return {:a 6 :b 12}

On Wed, Mar 25, 2009 at 11:27 PM, kinghajj <[email protected]> wrote:

>
> If not, I think it's pretty useful. There should be an easy way to
> apply functions to maps' values by keys.
>
> (defn update
>  [m & keyfuns]
>    (let [[key fun & rest] keyfuns]
>      (if (and key fun)
>        (recur (assoc m key (fun (key m))) rest)
>        m)))
>
> (def foo {:a 5 :b 7})
> (def bar (update foo :a inc :b #(+ 5 %)))
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to