1
package Main
2
3
object Twice {
4
def apply(x: Int): Int = x * 2
5
def unapply(z: Int): Option[Int] = if (z % 2 == 0) Some(z / 2) else None
6
}
7
8
object TwiceTest extends App {
9
val x = Twice(10)
10
x match { case Twice(n) => Console.println(n) } //prints 21
11