group<K> method

Map<K, List<T>> group<K>(
  1. K by(
    1. T item
    )
)

Groups Iterable via K by(T item)

if this is empty, the result of invoking is <K, List<T>>{}

Implementation

Map<K, List<T>> group<K>(K by(T item)) {
  final map = <K, List<T>>{};

  this.forEach((value) {
    final key = by(value);

    if (map.containsKey(key)) {
      map[key]!.add(value);
    } else {
      map[key] = <T>[value];
    }
  });

  return map;
}