0

I have a pattern matching code. X is a case class with too many parameters. I just want to do some check for its 3rd,4th parameter, and would like to use wildcard for rest of them.

o match {
  case Some(X(_,_, a,b, _*))) => // do something
 case _ => // do something else
}

This doesn't seem to work for me. What is correct way of using wildcard here?

Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • 1
    I don't think Scala provides capabilities to user wildcards in such cases, you have to specify all the arguments. Maybe easier would be replace pattern matching with `Option.map` or `Option.fold` and fetch field values from object – Ivan Kurchenko Mar 30 '21 at 04:06
  • 4
    Either do `case Some(x: X) => // use x.a & x.b`, or write a custom extractor as described e.g. [here](https://stackoverflow.com/questions/3474125/how-to-pattern-match-large-scala-case-classes) – Oleg Pyzhcov Mar 30 '21 at 06:04

0 Answers0