I have a tree of an unknown structure. First, I want to find a node containing a string of text, "Something". Then, after identifying the string's location in the tree, I want to update a different node relative to the string's location. The data is a deeply nested map with several branches of lists.
Is that possible with zippers?
I've studied this approach to editing trees: http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/. Problem is, I don't beforehand know the location of the string.
Yes! This is exactly the kind of task zippers where designed for.
zip/path
to find out where you are relative to the root. zip/up
, zip/down
, zip/left
etc to get to the node to modify. zip/root
to get your new map containing these changes. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With