Exhaustive Pattern Matching Of List Variants
Last updated
Was this helpful?
Last updated
Was this helpful?
ReasonML's switch
expression allows for powerful pattern matching. When using switch
to pattern match against a list, the compiler will be sure to warn you if you haven't accounted for all variants of a list.
this pattern-matching is not exhaustive. Here is an example of a value that is not matched: []
The compiler knows that a list can either be 1) empty ([]
) or 2) contain at least one value and another list ([a, ...rest]
). To ensure all variants are accounted for, we can include the []
case in our switch.