I want to match a Array whose first element is 0 or 1 or Null, below is the example:
def getTheta(tree: Node, coding: Array[Int]): Array[Double] = {
val theta = coding.take(coding.length - 1) match {
case Array() => tree.theta
case Array(0,_) => getTheta(tree.right.asInstanceOf[Node],coding.tail)
case Array(1,_) => getTheta(tree.left.asInstanceOf[Node],coding.tail)
}
theta
}
the tree class definition is :
sealed trait Tree
case class Leaf(label: String, popularity: Double) extends Tree
case class Node(var theta: Array[Double], popularity: Double, left: Tree, right: Tree) extends Tree
Actually I know that Array(0,__) or Array(1,_) is wrong, but what I care about is only the first element of the Array, and how can I match it?
Can someone help me?