Skip to content

Instantly share code, notes, and snippets.

@bfollington
Last active October 12, 2020 07:29
Show Gist options
  • Save bfollington/f98991fbf3cd05a0fea2988078608c87 to your computer and use it in GitHub Desktop.
Save bfollington/f98991fbf3cd05a0fea2988078608c87 to your computer and use it in GitHub Desktop.
(defn contains-in?
[m ks]
(not= ::absent (get-in m ks ::absent)))
(defn update-in-if-contains
[m ks f & args]
(if (contains-in? m ks)
(apply (partial update-in m ks f) args)
m))
;; (update-in-if-contains map [:key] map-fn)
(defn helpme [m]
(cond-> m
(:r m) (assoc :r [])
(:g m) (assoc :g [])))
;; will only replace :r if :r exists, concise way to do option.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment