E.g if I want to write
1 -> 2 match {
case 1 -> 2 => "matched"
case _ => "not matched"
}
// error: not found: value ->
rather than the slightly less obvious
1 -> 2 match {
case (1, 2) => "matched"
case _ => "not matched"
}
I have just such a thing! I like it because I find it more readable in many cases.
object -> {
def unapply[A, B](pair: (A, B)): Option[(A, B)] =
Some(pair)
}
Now you can do:
scala> val a -> b = 1 -> 2
a: Int = 1
b: Int = 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With