groupBy<K> method

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

Group elements by a key function

Implementation

Map<K, List<T>> groupBy<K>(K Function(T) keyFunction) {
  final groups = <K, List<T>>{};
  for (final element in this) {
    final key = keyFunction(element);
    groups.putIfAbsent(key, () => []).add(element);
  }
  return groups;
}