简体   繁体   English

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

[英]Scala, how to access the whole match: X match {case Y(z) as matched =>

Is there a syntax or way in scala to access the whole matched structure in a case statement? 在scala中是否有语法或方法来访问case语句中的整个匹配结构?

To clarify, if there was an "as" keyword, one could do this: 为了澄清,如果有一个“ as”关键字,可以这样做:

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM