假设我有一个Tree
包含 2 个成员对象的对象,right
并且left
.
tree
检查“右”和“左”字段是否为 Nil的惯用/正确方法是什么?
def count(tree: Tree, acc: Int) : Int = tree match {
case tree .right != Nil && tree .left != Nil => countLeftAndRight(...)
case tree .right != Nil => countOnlyRight(...)
case tree .left != Nil => countOnlyLeft(...)
_ => acc
}