sortedBy<T> function
Returns a copy of `items, stably sorted by sortKey.
The implementation uses collection.insertionSort
, which is optimized for
short lists.
Implementation
List sortedBy<T>(
Iterable<T> items,
int Function(T) sortKey, {
bool reverse = false,
}) {
final list = new List.from(items);
final comparator = reverse
? (a, b) => sortKey(a) - sortKey(b)
: (a, b) => sortKey(b) - sortKey(a);
insertionSort(list, compare: comparator);
return list;
}