Add stronger support for trees #71
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposal
Add a dedicated module to working with Graphs that are Trees.
Details
is_leaf?/2functionleaf_reduce/3leaf_map/2current_path/2Rationale
The Graph module provides some very excellent utilities for working with graphs, but is somewhat bare on the tree side of things. I had some use cases come up where a dedicated tree data structure would come in handy. The code that's outlined here is a pretty faithful replica of what I rolled at work to remediate that need. The main use case that I've had for this is creating trees of atoms that can be expanded to serve as a key list for a data structure that implements the access behaviour.
For example, here's the implementation of a function we've used to make sure a particular set of values in a large, deep map are non-empty:
I think it was actually this function that lead me to write in the
leaf_reducefunction. This one never got refactored though.I'm happy to make any changes or additions to it, or release it as it's own package if that's your preference. Some of what in here is probably not very consistent with the API, I know. I just didn't want this code to sit locked inside our application any more 👍 .