如何将带有when-condition的F#模式匹配转换为Scala?
我在F#中有以下代码:
match t0, t1 with
| "a", _ -> true
| b, "a" when not (b = "c") -> false
此主题还有另一篇文章Scala: Pattern matching when one of two items meets some condition,但我无法获得基线。
答案 0 :(得分:10)
我对F#不是很熟悉,但看起来应该几乎是1:1的转换。这是Scala版本:
(t0, t1) match {
case ("a", _) => true
case (b, "a") if b != "c" => false
}