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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -