scala - Pattern matching on case classes with * (varargs) parameter -
i have 2 case class like:
case class b(value:int) case class a(a:string, b:b*) extends alike and want pattern match on instance of a:
def foo(al:alike) = { al match { case a(a, bs) => ... } } scalac doesn't understand bs seq[b] , thinks 1 b. why case , how should pattern match on it?
it's varargs argument, need explain compiler explicitly. use following case expression:
def foo(al:alike) = { al match { case a(a, bs @ _*) => ... } }
Comments
Post a Comment