ComparableExtensions<T extends Object> extension

Extension that provides type-safe comparison methods for Comparable types.

This extension wraps Dart's Comparable interface and converts raw integer results to the more expressive Comparison enum, making comparison code more readable and maintainable.

Example:

// Standard approach (less readable)
if ('apple'.compareTo('banana') < 0) {
  print('apple is less than banana');
}

// With this extension (more readable)
if ('apple'.compareWith('banana') == Comparison.less) {
  print('apple is less than banana');
}
on

Methods

compareWith(T other) Comparison

Available on Comparable<T>, provided by the ComparableExtensions extension

Compares this value with another value of the same type.
isEqualTo(T other) bool

Available on Comparable<T>, provided by the ComparableExtensions extension

Checks if this value is equal to other.
isGreaterThan(T other) bool

Available on Comparable<T>, provided by the ComparableExtensions extension

Checks if this value is greater than other.
isGreaterThanOrEqualTo(T other) bool

Available on Comparable<T>, provided by the ComparableExtensions extension

Checks if this value is greater than or equal to other.
isLessThan(T other) bool

Available on Comparable<T>, provided by the ComparableExtensions extension

Checks if this value is less than other.
isLessThanOrEqualTo(T other) bool

Available on Comparable<T>, provided by the ComparableExtensions extension

Checks if this value is less than or equal to other.