Skip to content

Instantly share code, notes, and snippets.

@ustun
Last active March 1, 2017 22:06
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 ustun/d4e94a3977dce29b484d52dda5ce5bae to your computer and use it in GitHub Desktop.
Save ustun/d4e94a3977dce29b484d52dda5ce5bae to your computer and use it in GitHub Desktop.
(update-in foo [:bar :baz] ....)
What I meant was, each part of the path does an equality check of the original
compound data structure.
So, it says, give me the subsection of foo where key is *equal to* :bar.
Here, the predicate that says "key being equal to" is hard-coded.
What if it took any predicate?
That is, find
(update-in foo [some-func some-other-func] [transform])
It first transforms foo via some-func, to get a substructure.
Then, passes that substructure to find the nested substructure.
Finally, transforms it, and puts it back in place.
Of course, in the original version, due to equality checks on keys, there can only be one such value.
In the general version taking predicates, it can match multiple.
This essentially decomplects finding and transforming.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment