Algebraic Data Types (ADTs) to the rescue.
Here is the destructuring. Note the use of match
and case
.
object Main { def main(args: Array[String]) { println(s(One(7))) println(s(One("hello"))) println(s(None)) } def s[X](o: OneOrNone[X]) = o match { case One(o) => "got one! " + o case None => "don't got one" } }