There is a class with a very long list of the parameters for the constructor:
case class ClassA(a: Int, b: String, c: Int /*and so on*/)
I need to do a pattern matching against it:
val cls = getClassA
cls match {
case ClassA(a, _, _, _, _, /* and so on */) => Some(a)
case ClassA(_, _, c, _, _, /* and so on */) => Some(c)
case _ => None
}
And I need to capture the value of a
or c
. Is it possible not to specify all the other parameters by _
if I really don't need them?
val cls = getClassA
cls match {
case ClassA(a, _*) => Some(a)
case ClassA(_, _, c, _*) => Some(c)
case _ => None
}
It gave me the error: wrong number of arguments for pattern ClassA(a, b, /*and so on*/)