mapGrouped<K, G> method
Iterable<G>
mapGrouped<K, G>({
- required K? groupBy(
- T item
- required G groupBuilder(
- K? key,
- List<
T> items
Group elements with the groupBy Function and map those groups with the groupBuilder.
Implementation
Iterable<G> mapGrouped<K, G>({
required K? Function(T item) groupBy,
required G Function(K? key, List<T> items) groupBuilder,
}) {
final grouped = <K?, List<T>>{};
forEach((item) {
final key = groupBy(item);
grouped.putIfAbsent(key, () => []);
grouped[key]!.add(item);
});
return grouped.entries.map((entry) => groupBuilder(entry.key, entry.value));
}