I am trying to define a binary tree with the following definition:
trait Node {
val label: Int
}
case class BranchNode(override val label: Int, left: Option[Node], right: Option[Node]) extends Node
case class LeafNode(override val label: Int) extends Node
and then define a simple printTree method using Scala's pattern matching as below:
def printTree(aTree: Option[Node]): Unit = aTree match {
case None => print(".")
case Some(LeafNode(label)) => print(label)
case Some(BranchNode(label, left, right)) => "{" + printTree(left) + label + printTree(right) + "}"
}
The Intellij IDE warns me that the match may not be exhaustive. An Option can have None or Some as it's values. In case of Option[Node], it can either be Some(LeafNode) or Some(BranchNode). What other cases am I overlooking?
