replace if
This function compares the value in the 1st parameter with the comparison expression. If the value is true, then contents in the 2nd parameter replaces
those in the 1st parameter. This function is particularly interesting in combination with vectorization where every element in sets provided will be
compared, and, if appliable, the contents being replaced.
Vectorization: This function supports vectorization in the 1st and 2nd function parameter.
Instead of providing a single value, you can provide a set or even a nested set which contain multiple values.
The function will then process every value and its return value contains a corresponding set containing all results.
Indirect parameter passing is disabled
Vectorization is allowed in the 1st and 2nd function parameters
2
No. | Type | Description |
---|---|---|
1 input |
all types set |
Value to compare This value will be compared with the comparison expression in the 3rd function parameter. Vectorization: In this case, the corresponding element in the set will apply. |
2 input |
all types set |
Value to replace This value will be be returned if the comparison yields 'true'. Vectorization: In this case, the corresponding element in the set will apply. |
3 code |
comparison expression :string |
Comparison expression This parameter is a piece of code typically found on the right-hand side of a comparison with '=' or '<>'. Single values, ranges (e.g. 3..5), multiple values separated by commas are supported. For text comparison, wildcards are supported if the string is of type softquoted string. |
Type | Description |
---|---|
all types set |
Compared and possibly replaced results With vectorization applied, the comparison and replacements are performed for every element individually. |
echo( replace if( 2, -1, >2 ) ); // False case, output 2
echo( replace if( 3, -1, >2 ) ); // True case, output -1
echo;
echo( replace if( {1,2,3,4,5}, -1, >2 ) ); // Mix of both
2
-1
{1,2,-1,-1,-1}