Skip to content

Instantly share code, notes, and snippets.

@sjl
Created November 16, 2012 03:04
Show Gist options
  • Save sjl/4083603 to your computer and use it in GitHub Desktop.
Save sjl/4083603 to your computer and use it in GitHub Desktop.
(defmacro multi-update
[m & update-forms]
`(-> ~m ~@(map #(cons 'update-in %) update-forms)))
(multi-update {:a 10 :b 20 :c 30}
([:a] + 1)
([:b] + 1 1)
([:c] + 1 2))
; {:a 11 :b 22 :c 33}
@CampingScorpion
Copy link

You could do this, but most of the time it is overkill. All you're really doing is losing the update-ins that occur on those three lines. But what you lose is readability, because the reader needs to understand what multi-update does. Yes, it is a little less code/duplication, but I personally don't think the tradeoff is worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment