Created
November 5, 2014 14:13
-
-
Save msgodf/b31203dfc9d6cd7b16ec to your computer and use it in GitHub Desktop.
A function to update multiple parts of a structure.given a function that gives the locations of those parts.
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 update-at | |
"Takes a structure, a function that returns a list of paths (lists of keys) and a | |
function to apply at those paths within the structure. | |
For any paths that don't already exist in m, then f will be called with nil | |
and that path in the structure will be created with the result." | |
[m path-generation-fn f] | |
(reduce (fn [s v] (update-in s v f)) | |
m | |
(path-generation-fn m))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps this should just take a list of paths and leave the calling function to call the path generating function.