This is an excerpt from the Scala Cookbook (partially modified for the internet). This is one of the shortest recipes, Recipe 3.9, “How to assign the result of a match expression to a variable.”
You want to return a value from a
match expression and assign it to a variable, or use a
match expression as the body of a method.