sortedBy method
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)));