groupBy<K> method

Map<K, List<T>> groupBy<K>(
  1. K key(
    1. T item
    )
)

Groups items by a key. orders.groupBy((o) => o.status) → {paid: ..., pending: ...}

Implementation

Map<K, List<T>> groupBy<K>(K Function(T item) key) {
  final Map<K, List<T>> out = <K, List<T>>{};
  for (final T item in this) {
    (out[key(item)] ??= <T>[]).add(item);
  }
  return out;
}