Database |> Language |> Keywords |> 

WHEN

Contents

Definition

Sometimes when performing operations on a page you may take different courses of actions depending on the information in front of you. For control flow, we have a WHEN keyword.

|> WHEN <cond> THEN <body> ELSE <else>

Where, if the condition holds true, it proceeds with the actions defined in the body otherwise it proceeds with the actions defined in the else. The else does not have to be present and the line could simply be evaluating something when a condition holds true like so:

|> WHEN <cond> THEN <body>

In either of the above cases, after handling appropriately, it resumes with evaluating the following lines if present.

Condition

The condition follows the same rules as the condition used to filter in a WHERE expression.

|> WHEN <field> <comparator> <value> ...

Where the comparator can be any one of the available comparators and field refers to a field currently SELECTed into the state.

Body

The body follows the same rules as the body of a function and can include a single sequence of keywords or a pipe operator split sequence of instructions.

|> WHEN <cond> THEN <body>

In the case of pipe operator split instructions, it’s assumed that the remainder of the function it’s being defined inside of or the program it’s used in also sits in the conditional. This is to enforce intentionality with control flows similar to how Haskell enforces intentionality around using the IO monad.

some_function <|> <|
FROM is_it_thursday
|> WHEN <cond>
   THEN
   |> FROM another_website
   |> go_through_another_flow |

-- More code...

Else

The ELSE flow follows the same rules as the THEN flow but follows an ELSE keyword usage.

Example

Coming soon…


Related: