Frage

Is there a syntax or way in scala to access the whole matched structure in a case statement?

To clarify, if there was an "as" keyword, one could do this:

x match {
  case Y(z) as matched =>
    // do stuff both with "matched" and "z" here ...
  ...
}
War es hilfreich?

Lösung

You should be able to use the @ syntax:

x match {
  case matched @ Y(z) =>
    // do stuff both with "matched" and "z" here ...
  ...
}

From here

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top