In Scala, patterns can be defined independently of case classes. To this end, a method named unapply is defined to yield a so-called extractor.
If you want to change selection, open document below and click on "Move attachment"
Extractor Objects - Scala Documentation
<span>In Scala, patterns can be defined independently of case classes. To this end, a method named unapply is defined to yield a so-called extractor. For instance, the following code defines an extractor object Twice.
object Twice {
def apply(x: Int): Int = x * 2
def unapply(z: Int): Option[Int] = if (z%2 == 0) Some(z/2) else Non
Summary
status
not read
reprioritisations
last reprioritisation on
suggested re-reading day
started reading on
finished reading on
Details
Discussion
Do you want to join discussion? Click here to log in or create user.