postwalk
function
rewrite-clj.zip/postwalk
(postwalk [zloc f] [zloc p? f])Return zipper modified by an isolated depth-first post-order traversal.
Post-order traversal visits children before root.
For example, traversal order of `(1 (2 3 (4 5) 6 (7 8)) 9)` is:
1. `1`
2. `2`
3. `3`
4. `4`
5. `5`
6. `(4 5)`
7. `6`
8. `7`
9. `8`
10. `(7 8)`
11. `(2 3 (4 5) 6 (7 8))`
12. `9`
13. `(1 (2 3 (4 5) 6 (7 8)) 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/postwalk ...))
```
See [docs on sub editing](/doc/01-user-guide.adoc#sub-editing).
Examples
No examples yet. Be the first to add one!