ComparableX<T extends Comparable<T>> extension

Range and ordering helpers for any self-comparable type (String, DateTime, Duration, and your own Comparable types).

Numeric types are excluded by the bound because num already provides comparison operators and num.clamp.

on
  • T

Methods

coerceAtLeast(T min) → T

Available on T, provided by the ComparableX extension

Returns min when this value sorts before it, otherwise this value.
coerceAtMost(T max) → T

Available on T, provided by the ComparableX extension

Returns max when this value sorts after it, otherwise this value.
coerceIn(T min, T max) → T

Available on T, provided by the ComparableX extension

Constrains this value to the inclusive range [min, max].
coerceMax(T other) → T

Available on T, provided by the ComparableX extension

The larger of this value and other.
coerceMin(T other) → T

Available on T, provided by the ComparableX extension

The smaller of this value and other.
isInRange(T min, T max) → bool

Available on T, provided by the ComparableX extension

Whether this value falls within [min, max] inclusively.
isInRangeExclusive(T min, T max) → bool

Available on T, provided by the ComparableX extension

Whether this value falls strictly between min and max.

Operators

operator <(T other) → bool

Available on T, provided by the ComparableX extension

Whether this value sorts before other.
operator <=(T other) → bool

Available on T, provided by the ComparableX extension

Whether this value sorts before other or is equal to it.
operator >(T other) → bool

Available on T, provided by the ComparableX extension

Whether this value sorts after other.
operator >=(T other) → bool

Available on T, provided by the ComparableX extension

Whether this value sorts after other or is equal to it.