groupAndTransformBy<K, V> method
Map<K, Iterable<V> >
groupAndTransformBy<K, V>(
- K keySelector(
- E element
- V valueTransform(
- E element
Groups values returned by the valueTransform
function applied to each
element of the original collection by the key returned by the given
keySelector
function applied to the element and returns a Map where
each group key is associated with a Iterable
of corresponding values.
Implementation
Map<K, Iterable<V>> groupAndTransformBy<K, V>(
K Function(E element) keySelector,
V Function(E element) valueTransform,
) {
final groups = <K, Iterable<V>>{};
for (final element in this) {
final key = keySelector(element);
groups.putIfAbsent(
key,
() => where((element) => keySelector(element) == key)
.map((element) => valueTransform(element)),
);
}
return groups;
}