groupBy<M> method

Map<M, List<T>> groupBy<M>(
  1. M grouper(
    1. T
    )
)

Implementation

Map<M, List<T>> groupBy<M>(M Function(T) grouper) {
  Map<M, List<T>> map = {};

  for (final T k in this) {
    M t = grouper(k);

    if (!map.containsKey(t)) {
      map[t] = [];
    }

    map[t]!.add(k);
  }

  return map;
}