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.
I've added a number of useful functions. I appreciate that perhaps it would be slightly easier to review each in isolation, but I didn't quite have the time to slice everything up. So perhaps this can be a place to discuss the merits of the added functions and maybe another PR can than add whatever seems reasonable.
This adds:
mapWithContextBottomUp
,mapAccumulateWithContextBottomUp
,mapWithContextTopDown
,mapAccumulateWithContextTopDown
. These are very useful ways to map a tree, because in many applications of tree you need to have some information about the relationships of a node, not just it's label to create the proper transformation (for instance, one can use these to define ways to sum up quantitative information from the leaves into parent nodes, etc.). Once you add this context, the exact order in which the operation is performed becomes rather paramount.depth
is similar tocount
, but counts the number of levels in a tree. Very handy for drawing tree based visualisations, since this allows you to estimate how big to draw every layer of the tree to fit the whole thing in a fixed area.leaves
is somewhat similar toflatten
in that it returns a list, but in this case it only returns the leaves of the tree. My personal usecase is that for some treemaps you only really want to draw the leaf nodes, as the structure of the tree is implied by their layout.links
is again super useful for drawing trees, as generally this makes is the basis of drawing all the squiggly lines that actually connect the nodes. Another usecase is for laying out trees, as you can feed this into a many-body force simulation to lay out a force based tree layout.findBfs
finding stuff in trees is a pretty common usecase in trees... I names it explicitly with the idea that a futurefindDfs
could be added.sortWith
adds a simple way to change the order of the nodes within the rosetree. Again very useful for drawing trees, as many tree layout algorithms tend to provide more pleasing results when the nodes are sorted. I suppose that asort
andsortBy
variant could easily be provided, but they are rather trivially derived, so I didn't bother for now.