Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zipper.*_within APIs that operate on subtrees #134

Closed
zachallaun opened this issue May 22, 2024 · 1 comment · Fixed by #142
Closed

Add Zipper.*_within APIs that operate on subtrees #134

zachallaun opened this issue May 22, 2024 · 1 comment · Fixed by #142

Comments

@zachallaun
Copy link
Contributor

Currently, regardless of the focus of a zipper, functions like Zipper.find/2 will continue to search nodes outside of the focus (depth-first pre-order). There are cases where it's useful to operate only within the bounds of the current focus, however.

For instance:

zipper
|> Zipper.find(...) # find some parent node
|> Zipper.find_within(...) # find some child within the parent node
|> Zipper.update(...) # update the child somehow
|> Zipper.root() # navigate back to the root of the entire AST

There are other functions in Zipper, like traverse, that would also benefit from a *_within variant.

@NickNeck
Copy link
Contributor

That sounds like a good idea, @zachallaun.

The traverse functions already operate on the subtree, so they do not need the *_within version.

Perhaps we could also simply introduce an within/2 function.

zipper
|> Zipper.find(...) # find some parent node
|> Zipper.within(fn z -> Zipper.find(z, ...)) # find some child within the parent node
|> Zipper.update(...) # update the child somehow
|> Zipper.root() # navigate back to the root of the entire AST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants