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
-
- Comparable<
T>
- Comparable<
Methods
-
compareWith(
T other) → Comparison -
Available on Comparable<
Compares this value with another value of the same type.T> , provided by the ComparableExtensions extension -
isEqualTo(
T other) → bool -
Available on Comparable<
Checks if this value is equal toT> , provided by the ComparableExtensions extensionother. -
isGreaterThan(
T other) → bool -
Available on Comparable<
Checks if this value is greater thanT> , provided by the ComparableExtensions extensionother. -
isGreaterThanOrEqualTo(
T other) → bool -
Available on Comparable<
Checks if this value is greater than or equal toT> , provided by the ComparableExtensions extensionother. -
isLessThan(
T other) → bool -
Available on Comparable<
Checks if this value is less thanT> , provided by the ComparableExtensions extensionother. -
isLessThanOrEqualTo(
T other) → bool -
Available on Comparable<
Checks if this value is less than or equal toT> , provided by the ComparableExtensions extensionother.