prewalk
function
rewrite-clj.zip/prewalk
(prewalk [zloc f] [zloc p? f])Return zipper modified by an isolated depth-first pre-order traversal.
Pre-order traversal visits root before children.
For example, traversal order of `(1 (2 3 (4 5) 6 (7 8)) 9)` is:
1. `(1 (2 3 (4 5) 6 (7 8)) 9)`
2. `1`
3. `(2 3 (4 5) 6 (7 8))`
4. `2`
5. `3`
6. `(4 5)`
7. `4`
8. `5`
9. `6`
10. `(7 8)`
11. `7`
12. `8`
13. `9`
Traversal starts at the current node in `zloc` and continues to the end of the isolated sub-tree.
Function `f` is called on the zipper locations satisfying predicate `p?` and must return either
- nil to indicate no changes
- or a valid zipper
WARNING: when function `f` changes the location in the zipper, normal traversal will be affected.
When `p?` is not specified `f` is called on all locations.
To walk all nodes, you'll want to walk from the root node.
You can do this by, for example, using [[of-string*]] instead of [[of-string]].
```Clojure
(-> (zip/of-string* "my clojure forms")
(zip/prewalk ...))
```
See [docs on sub editing](/doc/01-user-guide.adoc#sub-editing).
Examples
No examples yet. Be the first to add one!