Skip to main content

Match expressions

Use match expressions to create expressions that are executed if a match assignment is true

match expr with
[] then "Empty"
[1 | rest] then "Has elements"

combining matches with AND and OR

use && or || to match the value with many expressions

match expr with
[] && [1] then "Do something"
[1 | rest] then "Do another thing"

Exhausting a match with _

k# will validate the match expression always returns a value. You can use _ to assert any value when create a match with infinite possible number of values.

match expr with
1 then "One"
2 then "Two"
_ then "Other value"

Calling functions in match clauses

If you want to use the expr into a match clause, you can combine many clauses with &&

match expr with
x && even x then "Even"
_ then "Odd"
note

To know more about the expressions used in match check match assignment expressions