You can write:
str match { case "foo" | "bar" => ... }
At first glance it looks like | could be an extractor object, however:
str match { case |("foo", "bar") => ... }
does not work. (And I can’t see how that could be implemented anyway.)
So it is a magic built-in operator?
(I believe I have seen this question on SO before, but it’s impossible to search for…)
Yes the pipe (
|) is a built-in for pattern matching (see the scala language reference). The Pattern matching section (section 8) defines in section 8.1.11 what is called Pattern Alternatives. The definition says:So yes, the pipe is a built-in that is context sensitive to pattern matching.