groupByToTransform<K, V, M extends KtMutableMap<K, KtMutableList<V>>> method

M groupByToTransform<K, V, M extends KtMutableMap<K, KtMutableList<V>>>(
  1. M destination,
  2. K keySelector(
    1. T
    ),
  3. V valueTransform(
    1. 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;
}