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 match instances of this class with some patterns?
For example, I want to implement function:
def printPrice(price: Price) = {
// implementation here
}
... that prints price is {some value}
for every price
that has value <= 9000
and price is over 9000
in all other cases.
For example, calling:
printPrice(new Price(10))
printPrice(new Price(9001))
should print:
price is 10
price is over 9000
How can I implement printPrice
using pattern matching?