naturalOrder<T> static method

Comparator<T> naturalOrder<T>()

Creates a comparator that compares Comparable objects in natural ascending order.

Suitable for any type that implements Comparable.


Example

final comp = Comparator.naturalOrder<int>();
final numbers = [5, 1, 3];
numbers.sort(comp.compare);
print(numbers); // [1, 3, 5]

Implementation

static Comparator<T> naturalOrder<T>() => _NaturalOrderComparator<T>();