if - Conditionally return a value
The if
function is useful for returning a value, if a given condition is true, otherwise returning some default value.
Syntax
Like many functions in DataPrime, if
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
condition | bool | true | Condition to be evaluated. Must return a bool |
then | any | true | Value if condition is true |
else | any | false | Value if condition is false |
Example - Adding a flag based on IP subnet
Consider the following document:
We're interested if a given IP address is in the 10.0.0.0/8
range. If it is, we don't want to keep calculating this, so we want to add a flag. We can do this using the if
clause:
Theme
Light