On Wed, 30 Mar 2011 10:21:41 -0700 (PDT)
Jeff Rose <ros...@gmail.com> wrote:

> Hola,
>   I'm looking for a function that updates a map value by calling a
> function on it.
> 
> (def foo {:a 1})
> 
> So instead of this:
>   (assoc foo :a (inc (:a foo)))            ; => {:a 2}
> 
> Something like this:
>   (map-fn foo :a inc)                        ; => {:a 2}
> 
> Does that exist somewhere, or should I be doing this in a different
> way?  If not, shouldn't it be included?

Possibly you want update-in:

(update-in foo [:a] inc)                ; -> {:a 2}

I'm not sure why there's not an "update" that replaces the list of
keys with a single key.

     <mike
-- 
Mike Meyer <m...@mired.org>             http://www.mired.org/consulting.html
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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