Add label collection methods, clean up API a bit #19
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.
This PR rebases @jhoon-stripe's additions in #15 and addresses @thomas-stripe's comments, and also cleans up a few things (starting along the lines of Tom's suggestions).
There's no rush on this, and it includes several (superficial) breaking changes, so if people don't think it's worthwhile I'm happy to scrap it—I just wanted to open the PR before I forget.
The main breaking changes have to do with consistency of the
fold*
andreduce*
signatures. Currently there's some variation in whether the label or children come first in functions that require both—e.g. inNodeRef#reduce
,TreeOps#fold
, etc., the label comes first, but inNodeRef#fold
andFullBinaryTreeOps#foldNode
the children come first:I've changed all signatures across the board to put the label first, since that seemed to be the more common case.
There's also some variation in whether folds or reductions that take two function arguments give each its own parameter list (
reduce
above) or combine them in a single list (all the others). In the case of two function arguments I don't think there's a strong case that one approach or the other is more idiomatic, and putting them together is slightly nicer for type inference (and I think more common here), so I've done that throughout.Another breaking change is related to @thomas-stripe's comment here suggesting a new
reduceFullBinaryTree
method. SincereduceNode
is already specific toFullBinaryTreeOps
, there's not really any reason it needs theIterable
in its signature, so I've rewritten it to be more or less Tom's suggestedreduceFullBinaryTree
(but following my new conventions above).@thomas-stripe also notes that
collectLabels
could go onTreeOps
, and this is also the case forcollectLabelsF
, so I've put both of them there.Unfortunately we can't make the breaking changes with a deprecation cycle, since a lot of the signatures are the same after erasure, but I'd be happy to take responsibility for writing up release notes and adding the commas / making the minor rearrangements that our code using bonsai will need.