associateByTo<K, V, M extends KtMutableMap<K, V> > method
M
associateByTo<K, V, M extends KtMutableMap<K, V> >(
- M destination,
- K keySelector(
- T
- V valueTransform(
- T
Populates and returns the destination
mutable map with key-value pairs,
where key is provided by the keySelector
function and
and value is provided by the valueTransform
function applied to elements of the given collection.
If any two elements would have the same key returned by keySelector
the last one gets added to the map.
Implementation
M associateByTo<K, V, M extends KtMutableMap<K, V>>(
M destination, K Function(T) keySelector,
[V Function(T)? valueTransform]) {
for (final element in iter) {
final key = keySelector(element);
final V value =
valueTransform == null ? element as V : valueTransform(element);
destination.put(key, value);
}
return destination;
}