Created
July 14, 2015 18:45
-
-
Save friemen/b2daf61c3d18a8d76184 to your computer and use it in GitHub Desktop.
Multi-path update
This file contains 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
user> (def data {:x 110 ::old {:x 100}}) | |
#'user/data | |
user> (update-in data [::old] merge {:x 110 :z 5}) | |
{:user/old {:z 5, :x 110}, :x 110} | |
user> (-> data | |
(update-in [::old] merge {:x 110 :z 5}) | |
(merge {:x 200})) | |
{:user/old {:z 5, :x 110}, :x 200} | |
user> (defn update-keep-old | |
[m k v] | |
(let [ov (m k)] | |
(-> m | |
(assoc k v) | |
(update-in [::old] k ov)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment