Friday, 16 August 2013

Checking Members for Nil

Checking Members for Nil

Let's say I have a Tree object with 2 member objects, right and left.
What's the idiomatic/right way to check if tree's "right" and "left"
fields are 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
}

No comments:

Post a Comment