groupBy<K> method
Group the list by f
.
Returns a Map with the keys and values returned by f
.
Implementation
Map<K, List<T>> groupBy<K>(K Function(T) f) {
final map = <K, List<T>>{};
for (final item in this) {
final key = f(item);
if (map.containsKey(key)) {
map[key]!.add(item);
} else {
map[key] = [item];
}
}
return map;
}