update/update-in

11 views
Skip to first unread message

mifrai

unread,
Apr 29, 2009, 6:54:23 PM4/29/09
to Clojure
Hi,

I was wondering why there was no "update" to "update-in"? But there is
an "assoc" to "assoc-in" and a "get" to a "get-in".

- Mike

David Nolen

unread,
Apr 29, 2009, 7:05:45 PM4/29/09
to clo...@googlegroups.com
Because update-in can use any function to do the update.

mifrai

unread,
Apr 29, 2009, 7:13:58 PM4/29/09
to Clojure
Thanks for the quick reply and I understand that's the functionality
of it.

But just like get-in is the recursive form of get - I'm just wondering
why there's no singular form of update-in.

I know it's not much more work to go (update-in map [:single-key] conj
3) - but from experience there tends be really good reasons behind
these kinds of decisions and I'm just curious.

On Apr 29, 4:05 pm, David Nolen <dnolen.li...@gmail.com> wrote:
> Because update-in can use any function to do the update.
>

David Nolen

unread,
Apr 30, 2009, 1:48:14 AM4/30/09
to clo...@googlegroups.com
I see what you mean, does seem like a useful addition:

(defn update [m k f & args]
  (assoc m k (apply f (k m) args)))

(update {:foo 0} :foo inc)

vs.

(assoc {:foo 0} :foo (inc (:foo {:foo 0})))
Reply all
Reply to author
Forward
0 new messages