groupMapReduce<K, B> method

IMap<K, B> groupMapReduce<K, B>(
  1. Function1<A, K> key,
  2. Function1<A, B> f,
  3. Function2<B, B, B> reduce
)
inherited

Partitions all elements of this collection by applying key to each element. Additionally f is applied to each element to generate a value. If multiple values are generating for the same key, those values will be combined using reduce.

Implementation

IMap<K, B> groupMapReduce<K, B>(
  Function1<A, K> key,
  Function1<A, B> f,
  Function2<B, B, B> reduce,
) {
  final m = <K, B>{};

  foreach((elem) {
    m.update(key(elem), (b) => reduce(b, f(elem)), ifAbsent: () => f(elem));
  });

  return IMap.fromDart(m);
}