groupBy<TKey> method
Groups elements of this iterable
by comparing the selector
result.
Implementation
Map<TKey, List<TValue>> groupBy<TKey>(TKey Function(TValue) selector) {
final map = <TKey, List<TValue>>{};
forEach((element) {
final key = selector(element);
if (map[key] == null) {
map[key] = [element];
} else {
map[key]!.add(element);
}
});
return map;
}