associateByTo<K> method

Map<K, T> associateByTo<K>(
  1. Map<K, T> destination,
  2. K keySelector(
    1. T
    )
)

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given collection and value is the element itself.

If any two elements would have the same key returned by keySelector the last one gets added to the map.

Implementation

Map<K, T> associateByTo<K>(Map<K, T> destination, K Function(T) keySelector) {
  for (var element in this) {
    destination[keySelector(element)] = element;
  }
  return destination;
}