Find node location in tree using Clojure Lightning

I have a tree of unknown structure. First, I want to find a node containing a string of text "Something". Then, after locating the row in the tree, I want to update another node relative to the row location . The data is a deeply nested map with several list branches.

Is this possible with lightning?

I learned this approach for editing trees: http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/ . The problem is that I do not know the location of the string in advance.

+7
clojure zipper tree
source share
1 answer

Yes! This is exactly what is intended for zippers intended for.

  • Press zip / next again until you find the node you are looking for.
  • Then call zip/path to find out where you belong to the root.
  • Then call zip/up , zip/down , zip/left , etc. to go to node for change.
  • update node
  • calling zip/root to get a new card containing these changes.
+7
source share

All Articles