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

Adds ZTree.find/2 #32

Closed
wants to merge 2 commits into from
Closed

Adds ZTree.find/2 #32

wants to merge 2 commits into from

Conversation

skbolton
Copy link
Contributor

@skbolton skbolton commented Sep 4, 2020

The find API will receive a lot of use in the Configuration module
where we will need it to locate State nodes that are the targets of
Transitions.

The implementation of find could use some work to use the ZTree in a
more clever way to do the traversal, but since this is all internal
details this implementation will allow us to move forward.

  • Add ZTree.rparent!/1
  • Add ZTree.find/2

Much of the ZTree api offers a `!` variant that is very useful in
testing. Looks like this function was missed because it wasn't being
used anywhere.
The `find` API will receive a lot of use in the `Configuration` module
where we will need it to locate `State` nodes that are the targets of
`Transition`s.

The implementation of `find` could use some work to use the ZTree in a
more clever way to do the traversal, but since this is all internal
details this implementation will allow us to move forward.

# Iterates over a zipper stepping to next node in a depth first search
# Once entire tree has been visited `{:ok, :complete, tree}` is returned
@spec next(t()) :: {:ok, t()} | {:ok, :complete, t()}
Copy link
Contributor Author

@skbolton skbolton Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was to make this a private function. But after getting this all done I think it makes sense to make this public. This function operates as an iterator that you can use to walk all the elements in the ZTree. It needs to maintain some state in order to do the traversal. I think I am going to take a little more time to clean it up.

@skbolton skbolton closed this Sep 11, 2020
@skbolton skbolton deleted the tree-find branch September 11, 2020 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant