groupByToTransform<K, V, M extends KtMutableMap<K, KtMutableList<V> > > method
M
groupByToTransform<K, V, M extends KtMutableMap<K, KtMutableList<V> > >(
- M destination,
- K keySelector(
- T
- V valueTransform(
- T
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 puts to the destination
map each group key associated with a list of corresponding values.
@return The destination
map.
Implementation
M groupByToTransform<K, V, M extends KtMutableMap<K, KtMutableList<V>>>(
M destination, K Function(T) keySelector, V Function(T) valueTransform) {
for (final element in iter) {
final key = keySelector(element);
final list = destination.getOrPut(key, () => mutableListOf<V>());
list.add(valueTransform(element));
}
return destination;
}