groupBy<K> method
Groups the elements in the list according to the keyFunction
.
Returns a map where each key corresponds to a list of elements that share that key.
Implementation
Map<K, List<T>> groupBy<K>(K Function(T) keyFunction) {
return fold(<K, List<T>>{}, (Map<K, List<T>> map, T element) {
final K key = keyFunction(element);
map.putIfAbsent(key, () => []).add(element);
return map;
});
}