Hi,
I'm using clojure.zip to edit a tree by visiting each location using zip/next, possibly using zip/replace to alter the tree.
There are cases where I replace a part of the tree with another tree that will/must not be visited, but I couldn't find a good way to skip nodes, since
(zip/next (zip/replace loc new-subtree)) will walk right into my new tree, and I can't use (zip/right (zip/replace loc new-subtree)) as the replaced location might already be the rightmost.
Is there a built-in function I missed, or a zip enhancement library I could use?
(defn skip
"returns the next location that is not a child of this one"
[loc]
(if (or (z/end? loc) (nil? loc))
loc
(loop [loc loc]
(or (z/right loc)
(recur (z/up loc))))))
I came up with this replacement, does that seem like a good idea, or am I using zip completely wrong (because what I really would like to do is iterate backwards through the tree, starting at the end, using zip/prev; but there's also no function to just jump to the end as far as I can tell)
Cheers,
--
pascal