sortedBy<K extends Comparable<K>> method Null safety

List<T> sortedBy<K extends Comparable<K>>(
  1. K keyOf(
    1. T element
    )
)

Creates a sorted list of the elements of the iterable.

The elements are ordered by the natural ordering of the property keyOf of the element.

Implementation

List<T> sortedBy<K extends Comparable<K>>(K Function(T element) keyOf) {
  var elements = [...this];
  mergeSortBy<T, K>(elements, keyOf, compareComparable);
  return elements;
}