Skip to content

Instantly share code, notes, and snippets.

@dimitarg
Created June 20, 2017 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimitarg/bacb32bfec15e34d1ddd01c552995724 to your computer and use it in GitHub Desktop.
Save dimitarg/bacb32bfec15e34d1ddd01c552995724 to your computer and use it in GitHub Desktop.
private static <A> Option<Tree<A>> filterTopDown(Tree<A> tree, Predicate<A> pred)
{
if (!pred.test(tree.root()))
{
return none();
}
Stream<Tree<A>> filteredChildren = tree.subForest().f().map(child -> filterTopDown(child, pred)).filter(x -> x.isSome())
.map(x -> x.some());
return some(node(tree.root(), filteredChildren));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment