0

How is it possible to convert a F# pattern-matching with when-condition to Scala?

I have the following code in F#:

match t0, t1 with
| "a", _ -> true
| b, "a" when not (b = "c") -> false

There is another post on this topic Scala: Pattern matching when one of two items meets some condition, but I can't get the baseline.

John Smith
  • 771
  • 8
  • 25

1 Answers1

10

I'm not very familiar with F#, but looks like it should be almost 1:1 conversion. Here is Scala version:

(t0, t1) match {
    case ("a", _) => true
    case (b, "a") if b != "c" => false
}
tenshi
  • 26,268
  • 8
  • 76
  • 90
  • For the pattern ("c", "a") this leads to an error. If b is always != c, the test is superflous, if not, a default case is necessary. Maybe this problem is already in the F#-code. – user unknown Nov 15 '11 at 23:21