sortedBy<K extends Comparable> method

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

Returns a new list sorted ascending by key.

Implementation

List<T> sortedBy<K extends Comparable<dynamic>>(K Function(T) key) {
  final copy = [...this];
  copy.sort((a, b) => key(a).compareTo(key(b)));
  return copy;
}