Skip to content

Instantly share code, notes, and snippets.

@bka9
Last active August 29, 2015 14:08
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 bka9/77e35d786b93ba4d6b30 to your computer and use it in GitHub Desktop.
Save bka9/77e35d786b93ba4d6b30 to your computer and use it in GitHub Desktop.
Using futures to count children with name
case class Node(name: String, children: List[Node])
def count(node: Node, name: String) = {
if(node.children == null && node.name == name) future{1}
else if(node.children == null) future{0}
else if(node.name == name{
future{
1 + node.children.foldLeft(0)((total,child) => total + count(child,name))
}
}
else{
future{
0 + node.children.foldLeft(0)((total,child) => total + count(child,name))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment