Last active
March 1, 2017 22:06
-
-
Save ustun/d4e94a3977dce29b484d52dda5ce5bae 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
(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