Created
November 16, 2012 03:04
-
-
Save sjl/4083603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could do this, but most of the time it is overkill. All you're really doing is losing the
update-in
s 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.