Created
June 20, 2017 12:43
-
-
Save dimitarg/bacb32bfec15e34d1ddd01c552995724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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