sortedByString method

List<T> sortedByString(
  1. String valueProvider(
    1. T element
    )
)

Returns this as sorted list using the valueProvider function that produces character values as base for sorting.

Example:

['c', 'b', 'a'].sortedByNum((c) => c); // ['a', 'b', 'c']
persons.sortedByString((p) => p.name); // sort persons alphabetically

Implementation

List<T> sortedByString(String Function(T element) valueProvider) {
  ArgumentError.checkNotNull(valueProvider, 'valueProvider');
  return sortedBy((a, b) => valueProvider(a).compareTo(valueProvider(b)));
}