1.1 KiB
1.1 KiB
OR Patterns
An OR pattern in AVAP allows you to specify multiple patterns separated by vertical bars ( | ). The OR pattern attempts to match each of its subpatterns with the subject value in order. If any of the subpatterns match, the OR pattern is considered successful. If none of the subpatterns match, the OR pattern fails.
or_pattern ::= "|".closed_pattern+
Here's how you can use OR patterns in practice:
match value:
case 1 | 2 | 3:
# Code to execute if value is 1, 2, or 3
case "hello" | "world":
# Code to execute if value is "hello" or "world"
case _:
# Code to execute if value does not match any of the above
In this example:
- The first case will match if
valueis either 1, 2, or 3. - The second case will match if
valueis either "hello" or "world". - The last case is a catch-all pattern that will execute if none of the previous patterns match.
OR patterns provide a concise way to handle multiple possible values or types, simplifying pattern matching and making your code more readable.