如何返回模式匹配的元素?

时间:2015-02-01 00:24:29

标签: scala

我想匹配String返回的someFunction,并且默认情况下会从String返回someFunction

someFunction(input) match {
  case "123" => "234"
  case "234" => "345"
  case _ => _
}

case _ => _返回someFunction(input)实际返回的内容。这可能吗?

1 个答案:

答案 0 :(得分:6)

您只需要命名默认情况:

someFunction(input) match {
  case "123" => "234"
  case "234" => "345"
  case x => x
}