I'm currently playing around with Scala's pattern matching. What I know so far is, that an extractor named like an operator gets left associative and an extractor named like a method or type is right associative.
My current approach looks something like this:
object Foo {
def unapply(tokens: Seq[String]): Option[(Seq[String], String)] = // do something
}
// ...
object Main extends App {
Seq("hi", "bye") match {
case xs Foo foo2 Foo foo1 => // do something with result
case _ => // handle error
}
}
This is somewhat unpleasuring as it requires me to write my matches reverse or matching them reverse due to the right associativity. I would prefer if I could write something like this:
object Foo {
def unapply(tokens: Seq[String]): Option[(String, Seq[String])] = // do something
}
// ...
object Main extends App {
Seq("hi", "bye") match {
case foo1 Foo foo2 xs => // do something with result
case _ => // handle error
}
}
Is there any way to keep some readable name for an extractor and make it left associative?
Thanks in advance.