Pattern Matching Gotcha

Pattern matching construct in Scala is powerful. It allows you to easily assign values to local variables, match against literal values, and deconstruct a more complex type into component parts. Most of the time this ends up being very intuitive. Here are a few trivial examples:

So what’s the gotcha? A local variable in the match scope will shadow a variable that starts with a lowercase letter. This is different than a variable that starts with an uppercase letter.

The last case shows this behavior in action.