I want to compare a given string to a given set of other strings. Instead of using a series of if
s I went for the more concise pattern matching way, and intuitively wrote:
val s = "match"
val s1 = "not match"
val s2 = "not really a match"
val s3 = "match"
s match {
case s1 => println("Incorrect match 1")
case s2 => println("Incorrect match 2")
case s3 => println("Match")
case _ => println("Another incorrect match")
}
Which, surprisingly to me, resulted in:
Incorrect match 1
And my compiler warning that beyond case s2 =>...
my code is unreachable. Why doesn't my approach work? And how can I "match" against a string?