Skip to content

add filter function to tree data structure #31

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

Closed
brucou opened this issue Nov 1, 2015 · 2 comments
Closed

add filter function to tree data structure #31

brucou opened this issue Nov 1, 2015 · 2 comments

Comments

@brucou
Copy link

brucou commented Nov 1, 2015

Given a tree, return a tree of the same structure made up of the objects returned by the callback which is executed at each node. If, however, at a given node the callback returns a falsy value, then the current node and all of its descendents will be pruned from the output tree.

Similar to Array.filter

Example : node.filter(function (node, parent_node, index, root_node) {/*SOMETHING*/})

NOTE : this is closely linked to this existing issue : #22

@joaonuno
Copy link
Owner

joaonuno commented Nov 1, 2015

Please see my comment on issue #30

I already have a solution to the issue #22 that hopefully will cover the different traversal strategies but have not implemented it yet.

@joaonuno joaonuno closed this as completed Nov 1, 2015
@brucou
Copy link
Author

brucou commented Aug 31, 2018

With a reducing traversal, stop at any level is relatively easy to implement : https://github.com/brucou/functional-rose-tree

A function pruneWhen can additionally allow to remove part of the tree, based on a predicate. This is another indirect way to implement stopping conditions (if a part of the tree is removed, it can be traversed).

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

No branches or pull requests

2 participants