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

Expose methods for mutable trees #35

Open
milibopp opened this issue Jan 10, 2015 · 1 comment
Open

Expose methods for mutable trees #35

milibopp opened this issue Jan 10, 2015 · 1 comment

Comments

@milibopp
Copy link
Owner

Currently, methods such as insert are private, since (1) they cannot guarantee the internal invariants of a tree completely, and (2) their signature is inconsistent between Tree and PureTree.

However, it may well be sensible to access the tree mutably after its construction. Therefore, it is necessary to provide a public interface that fulfills the missing properties mentioned above.

Furthermore, there may be more methods than insert to consider, e.g.

  • remove(filter) removes objects based on some filter.
  • collapse(filter) collapses nodes to empty nodes based on some filter.
  • extend(iterator) inserts all elements from the iterator into the tree. (stdlib trait Extend)
@milibopp
Copy link
Owner Author

In order to follow the immutable-by-default principle, all these methods should come in two flavours:

  • A method that mutates the tree:
fn collapse_mut<F: FnMut(&Node) -> bool>(&mut self, filter: F);
  • A method that makes a copy of the tree with the appropriate changes
fn collapse<F: FnMut(&Node) -> bool>(&self, filter: F) -> Self;

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

No branches or pull requests

1 participant