Equivalent to switch in many other languages.
Docs
See match (docs)
Difference from switch in other languages
Crash-course for people who are familiar with switch statements
- Replace
switchwithmatch. - Remove
case. - Remove any
breaks. - Change
defaultto a single underscore.
Syntax
match <test value>:
<pattern(s)>:
<block>
<pattern(s)> when <pattern guard>:
<block>
<...>