Created
January 29, 2015 04:30
-
-
Save mwmitchell/161a1b9c1dc7797c3e95 to your computer and use it in GitHub Desktop.
maybe-update-in
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
;; Like update-in, but doesn't call the fn | |
;; (or set a key) if the key doesn't already exist. | |
(defn maybe-update-in [data ks fn] | |
(if ((last ks) (-> data (get-in (butlast ks)) keys set)) | |
(update-in data ks fn) | |
data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment