As an example I have a Sequence like this
abstract class MySeq[+A] {
def head: A = ???
def tail: MySeq[A] = ???
}
case object EmptySeq extends MySeq[Nothing]
case class Cons[+A](override val head: A, override val tail: MySeq[A]) extends MySeq[A]
object MySeq {
def unapply[A](arg: MySeq[A]): Option[Seq[A]] = ???
}
and I wanted to do pattern matching in this ADT.
For instance
val mySeq: MySeq[Int] = Cons(1, Cons(2, Cons(3, EmptySeq)))
val decomposed = mySeq match {
case MySeq(1, 2, _*) => "starting with 1, 2"
case _ => "something else"
}
println(decomposed)
But this give an error: Wrong number of arguments for extractor found 3 expected 1
I miss something.
is it possible to do this?