-
-
Save tomjack/faafe19ec35ed632339c to your computer and use it in GitHub Desktop.
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
(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