Pattern Matching with Option
Using match with Option allows explicit distinction between Some(v) and None cases, with different handling logic in each branch. This is the most common and clearest way to handle Option.
case Some(v) binds the inner value of Option to variable v, which can be used in the branch code. case None handles the case when the value is empty.
The where guard can further refine matching conditions. For example, case Some(s) where s >= 90 only matches Some where the inner value is greater than or equal to 90. Guards must be boolean expressions, placed after the pattern and before =>.
The code on the right demonstrates how to use patterns and guards to convert scores to letter grades, with a default value for missing scores.
match requires exhaustive coverage of all cases. When handling Option, both Some and None branches must be included.Try modifying the getLetterGrade function to add more score ranges (like A+, A-).