groupBy<S, T> function

Map<T, List<S>> groupBy<S, T>(
  1. Iterable<S> values,
  2. T key(
    1. S

Groups the elements in values by the value returned by key.

Returns a map from keys computed by key to a list of all values for which key returns that key. The values appear in the list in the same relative order as in values.


Map<T, List<S>> groupBy<S, T>(Iterable<S> values, T Function(S) key) {
  var map = <T, List<S>>{};
  for (var element in values) {
    (map[key(element)] ??= []).add(element);
  return map;