orderByE<TKey> method

Enumerable<T> orderByE <TKey>(Selector<T, TKey> keySelector, { EqualityComparer<TKey> keyComparer })

Sorts the enumeration in ascending (least-to-greatest) order.

First, orderByE iterates over the entire enumerable, creating a list of keys generated by keySelector associated to their corresponding elements. Then a QuickSort algorithm is applied to the keys, using the sorter property in keyComparer to determine sort order. Afterwards, the resulting enumerable will consist of the elements in the source enumerable in the order determined by the sorted list of keys.

When the type of the enumerable is one of the below types, the EqualityComparer can be omitted. In this case, the function defaults to predefined minimum functions depending on the type:

  • Numeric types (num, int, double) will be sorted by their values in ascending order.
  • String types will be sorted in alphabetic order.

If the enumerable type is not one of these types and the EqualityComparer is not provided, the order of the resulting enumerable is unpredictable.

If the enumerable is already sorted in ascending order, the resulting enumerable will be unchanged.

Implementation

Enumerable<T> orderByE<TKey>(Selector<T, TKey> keySelector,
    {EqualityComparer<TKey> keyComparer}) {
  ArgumentError.checkNotNull(keySelector);
  return InternalOrderedEnumerable(this, keySelector, keyComparer, false);
}