Scala,如何访问整个匹配:X match{case Y(z)as matched=>;

Scala,如何访问整个匹配:X match{case Y(z)as matched=>;,scala,pattern-matching,case-class,Scala,Pattern Matching,Case Class,scala中是否有语法或方法来访问case语句中的整个匹配结构 为了澄清,如果有“as”关键字,可以这样做: x match { case Y(z) as matched => // do stuff both with "matched" and "z" here ... ... } 您应该能够使用@语法: x match { case matched @ Y(z) => // do stuff both with "matched" and "z"

scala中是否有语法或方法来访问case语句中的整个匹配结构

为了澄清,如果有“as”关键字,可以这样做:

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

您应该能够使用
@
语法:

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

中,调用可能的重复项。