associateBy<K> method

  1. @useResult
KtMap<K, T> associateBy<K>(
  1. K keySelector(
    1. T
    )
)

Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element.

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

The returned map preserves the entry iteration order of the original collection.

Implementation

@useResult
KtMap<K, T> associateBy<K>(K Function(T) keySelector) {
  return associateByTo<K, T, KtMutableMap<K, T>>(
      linkedMapFrom<K, T>(), keySelector);
}