Lets assume that I have a plain third party (i.e. I cannot modify it) class defined like:
class Price(var value: Int)
Is this possible to m
You can create custom extractor:
package external {
class Price(var value: Int)
}
object Price {
def unapply(price: Price): Option[Int] = Some(price.value)
}
def printPrice(price: Price) = price match {
case Price(v) if v <= 9000 => println(s"price is $v")
case _ => println("price is over 9000")
}
printPrice(new Price(10))
printPrice(new Price(9001))
For case classes compiler generates it automaticaly. I think in your case extractors is overkill, but may be it's only simplified sample.