```
abstract class Node(id: Long, name: String) {
  def find(id: Long) = if (this.id == id) Some(this) else None
}
case class Contact(id: Long, name: String, phone: String) extends Node(id, name)
case class Group(id: Long, name: String, entries: Node*) extends Node(id, name) {
  override def find(id: Long): Option[Node] = {
    super.find(id) orElse entries.flatMap(e => e.find(id)).headOption
  }
}
val tree =
  Group(0, "Root"
      , Group(10, "Shop", Contact(11, "Alice", "312"))
      , Group(20, "Workshop"
          , Group(30, "Tyres", Contact(31, "Bob", "315"), Contact(32, "Greg", "319"))
          , Contact(33, "Mary", "302"))
      , Contact(1, "John", "317"))
println(tree.find(32))

```

Tree data is built from *Contact*s and *Group*s (w/ sub-Groups and Contacts). I want to find a node with specific *id*. Currently I traverse *Group*'s members using:

```
entries.flatMap(e => e.find(id)).headOption

```

but it isn't optimal because I check all child entries instead of break upon first finding. 

I'd appreciate your help in magic *Scala Wold*. Thanks.