【问题标题】:Scala, how to access the whole match: X match {case Y(z) as matched =>Scala,如何访问整个匹配:X match {case Y(z) as match =>
【发布时间】:2013-07-31 22:57:43
【问题描述】:

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

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

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

【问题讨论】:

标签: scala pattern-matching case-class


【解决方案1】:

您应该能够使用@ 语法:

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

来自here

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-26
  • 2019-07-25
  • 2017-08-14
  • 2018-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多