Hi, take this example:
case class A(a: String)
object A {
def unapply(s: String): Option[A] = {
Some(A(s))
}
}
case class B(a: String)
object B {
def unapply(s: String): Option[B] = {
Some(B(s))
}
}
def testA(args: List[String]) = {
args match {
case A(a) :: B(b) :: "other" :: Nil =>
}
}
Is it possible to have a
and b
refactored to a separate class AB
:
case class AB(a: A, b: B)
So that one can have this pattern-matching?
def testAB(args: List[String]) = {
args match {
case AB((a, b)) :: "other" :: Nil =>
}
}
And have a
and b
be of the correct type (A
and B
)?
Thanks.