Control Flow Operators
Control flow operators allow you to create conditional logic and manage the flow of rule evaluation in DataLogic-rs.
if
and
or
!
if
The if
operator evaluates a condition and returns one of two values based on the result.
Syntax
{ "if": [condition, true_result, false_result] }
Parameters
Parameter | Description |
---|---|
condition | Expression to evaluate as boolean |
true_result | Value to return if condition is true |
false_result | Value to return if condition is false |
Example: Simple Condition
Rule:
Data:
Result:
Example: Nested Conditions
Rule:
Data:
Result:
and
The and
operator returns true if all of its arguments are truthy, and the last truthy value otherwise.
Syntax
{ "and": [expr1, expr2, ...] }
Parameters
Parameter | Description |
---|---|
expressions | Array of expressions to evaluate |
Example: Multiple Conditions
Rule:
Data:
Result:
Example: Short-Circuit Evaluation
Rule:
Data:
Result:
or
The or
operator returns the first truthy argument, or the last argument if all are falsy.
Syntax
{ "or": [expr1, expr2, ...] }
Parameters
Parameter | Description |
---|---|
expressions | Array of expressions to evaluate |
Example: Alternative Conditions
Rule:
Data:
Result:
Example: Short-Circuit Evaluation
Rule:
Data:
Result:
!
The !
operator returns the logical negation of its argument.
Syntax
{ "!": expr }
Parameters
Parameter | Description |
---|---|
expression | Expression to negate |