Skip to content

cmp

Written as cmp(argnum flags):options in a transform expression.

Minimum arguments 2
Maximum arguments 2
Default arguments 2
Argument modes MULTIPLE

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
Input args: [10,20]
Transforms: "cmp:"
Output: -1
Input args: [3.14,2.71]
Transforms: "cmp:"
Output: 1
Input args: [10,20]
Transforms: "cmp:<"
Output: true

With explicit comparator (less than or equal)

Section titled “With explicit comparator (less than or equal)”
Input args: [3.14,2.71]
Transforms: "cmp:<="
Output: false
Input args: [5,3.14]
Transforms: "cmp:"
Output: 1
Input args: ["apple","banana"]
Transforms: "cmp:"
Output: -1
Input args: ["2023-01-01T00:00:00","2023-01-02T00:00:00"]
Transforms: "cmp:"
Output: -1
Input args: [100,100]
Transforms: "cmp:"
Output: 0
Input args: [100,"xyz"]
Transforms: "cmp:"
Output: N/A
Error: "Cannot compare int and str"