asInt method

int asInt()

Converts this comparison result to its integer representation.

Returns:

This representation is compatible with standard comparison functions like those in sorting algorithms or Comparable.compareTo.

Example:

Comparison.less.asInt();   // -1
Comparison.equal.asInt();  // 0
Comparison.greater.asInt(); // 1

Implementation

int asInt() => switch (this) {
  .less => -1,
  .equal => 0,
  .greater => 1,
};