문제

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 ...
  ...
}
도움이 되었습니까?

해결책

You should be able to use the @ syntax:

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

From here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top