Non-linear pattern matching in Scala