Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created August 11, 2009 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomjack/faafe19ec35ed632339c to your computer and use it in GitHub Desktop.
Save tomjack/faafe19ec35ed632339c to your computer and use it in GitHub Desktop.
(defn map-and-update-in [m [k & ks] f]
(let [value (k m)]
(assoc m k (if ks
(if (map? value)
(map-and-update-in value (seq ks) f)
(map #(map-and-update-in % (seq ks) f) value))
(f value)))))
user> (map-and-update-in {:foos [{:bar {:bizzes [{:bam 3} {:bam 53}] }}
{:bar {:bizzes [{:bam 5} {:bam 75}] }}]}
[:foos :bar :bizzes :bam] inc)
{:foos ({:bar {:bizzes ({:bam 4} {:bam 54})}} {:bar {:bizzes ({:bam 6} {:bam 76})}})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment