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
switch
withmatch
. - Remove
case
. - Remove any
break
s. - Change
default
to a single underscore.
Syntax
match <test value>:
<pattern(s)>:
<block>
<pattern(s)> when <pattern guard>:
<block>
<...>