#extractor-objects #scala
The apply method is not necessary for pattern matching. It is only used to mimick a constructor. val x = Twice(21) expands to val x = Twice.apply(21).
If you want to change selection, open document below and click on "Move attachment"

Extractor Objects - Scala Documentation
use an invocation of Twice.unapply, which is used to match any even number; the return value of the unapply signals whether the argument has matched or not, and any sub-values that can be used for further matching. Here, the sub-value is z/2 <span>The apply method is not necessary for pattern matching. It is only used to mimick a constructor. val x = Twice(21) expands to val x = Twice.apply(21). The return type of an unapply should be chosen as follows: * If it is just a test, return a Boolean. For instance case even() * If it returns a single sub-value of type T, return an Opti