cmp
Written as cmp(argnum flags):options in a transform expression.
| Minimum arguments | 2 |
| Maximum arguments | 2 |
| Default arguments | 2 |
| Argument modes | MULTIPLE |
Documentation
Section titled “Documentation”Compare 2 arguments and return whether the left hand side is less/greater than or equal to the right hand side.
By default, the comparison result is returned as -1, 0, or 1, indicating the left hand side is:
- less than, or
- equal to, or
- greater than the right hand side.
However, any of below explicit comparators can be specified in the options string:
<(less than)<=(less than or equal to)=(equal to)>(greater than)>=(greater than or equal to)
and in this case, a boolean true/false will be returned instead of -1, 0, or 1.
Note:
- the LHS and RHS must be comparable, otherwise error will be raised
| Flag | Letter |
|---|---|
| spread_input | s |
| noncaptive_input | I |
Examples
Section titled “Examples”Numbers (same type) - less than
Section titled “Numbers (same type) - less than”Input args: [10,20]Transforms: "cmp:"Output: -1Numbers (same type) - greater than
Section titled “Numbers (same type) - greater than”Input args: [3.14,2.71]Transforms: "cmp:"Output: 1With explicit comparator (less than)
Section titled “With explicit comparator (less than)”Input args: [10,20]Transforms: "cmp:<"Output: trueWith explicit comparator (less than or equal)
Section titled “With explicit comparator (less than or equal)”Input args: [3.14,2.71]Transforms: "cmp:<="Output: falseNumbers (mixed type)
Section titled “Numbers (mixed type)”Input args: [5,3.14]Transforms: "cmp:"Output: 1Strings
Section titled “Strings”Input args: ["apple","banana"]Transforms: "cmp:"Output: -1Datetimes
Section titled “Datetimes”Input args: ["2023-01-01T00:00:00","2023-01-02T00:00:00"]Transforms: "cmp:"Output: -1Equal values
Section titled “Equal values”Input args: [100,100]Transforms: "cmp:"Output: 0In comparable values raise error
Section titled “In comparable values raise error”Input args: [100,"xyz"]Transforms: "cmp:"Output: N/AError: "Cannot compare int and str"