sortedBy method

List<T> sortedBy(
  1. Comparable<Object?> selector(
    1. T element
    )
)

A new list sorted ascending by the key returned from selector.

people.sortedBy((p) => p.age);

Implementation

List<T> sortedBy(Comparable<Object?> Function(T element) selector) =>
    toList()..sort((a, b) => selector(a).compareTo(selector(b)));