Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created January 29, 2015 04:30
Show Gist options
  • Save mwmitchell/161a1b9c1dc7797c3e95 to your computer and use it in GitHub Desktop.
Save mwmitchell/161a1b9c1dc7797c3e95 to your computer and use it in GitHub Desktop.
maybe-update-in
;; 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