DRAFTThis page is not published. Only visible in development mode.

Match

match is RQL's multi-way branch. It is an expression: it selects one arm, evaluates it, and produces that value - in a let binding, in a map projection, anywhere an expression fits. Where if/else answers a yes/no question, match replaces a ladder of them.

Value match

The first form compares one value against literal arms. else is the catch-all; with it, the expression always produces a value:

$ Match a Value Against Literal Arms
$ ctrl+enter to run

Searched match

The second form has no scrutinee - each arm is a full boolean condition. This is the shape for ranges and anything else that is not a simple equality:

$ Match on Conditions
$ ctrl+enter to run

Arms are checked top to bottom and the first true one wins, so order them from most specific to least. A broad condition listed first silently shadows everything below it:

$ The First True Arm Wins
$ ctrl+enter to run

Classifying rows

Both forms work per row inside a pipeline - reference columns directly in the arms. This is the workhorse for bucketing and labeling:

$ Classify Rows in a Pipeline
$ ctrl+enter to run

Match inside map and extend is covered from the pipeline side in Transforms: Match.

match and none

Value-match arms compare by equality, and equality against none never matches - not even a literal none arm. The arm below is dead code; the row with the missing score falls through to else and you never see "missing":

$ A none Arm Never Matches
$ ctrl+enter to run

To branch on missingness, use a searched match with an is::none arm - it always returns a definite true or false, which also makes this the idiom for substituting defaults:

$ Test for none with a Searched Arm
$ ctrl+enter to run
Two branches? Use if
For a plain yes/no decision, an if/else expression says the same thing with less ceremony. Reach for match when there are three or more outcomes, or when the arms are a value's known cases.