Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A function to update multiple parts of a structure.given a function that gives the locations of those parts.
(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)))
@msgodf
Copy link
Author

msgodf commented Nov 5, 2014

Perhaps this should just take a list of paths and leave the calling function to call the path generating function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment