groupByTransform<K, V> method
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 list of corresponding values.
The returned map preserves the entry iteration order of the keys produced from the original collection.
Implementation
KtMap<K, KtList<V>> groupByTransform<K, V>(
K Function(T) keySelector, V Function(T) valueTransform) {
final groups = linkedMapFrom<K, KtList<V>>();
for (final element in iter) {
final key = keySelector(element);
final list = KtMutableMapExtensions(groups)
.getOrPut(key, () => mutableListOf<V>()) as KtMutableList<V>;
list.add(valueTransform(element));
}
return groups;
}