associateByTransform<K, V> method

  1. @useResult
KtMap<K, V> associateByTransform<K, V>(
  1. K keySelector(
    1. T
    ),
  2. V valueTransform(
    1. T
    )
)

Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element. The element can be transformed with valueTransform.

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, V> associateByTransform<K, V>(
    K Function(T) keySelector, V Function(T) valueTransform) {
  final map =
      associateByTo(linkedMapFrom<K, V>(), keySelector, valueTransform);
  // TODO ping dart-lang/sdk team to check type bug
  // When in single line: type 'DartLinkedHashMap<int, String>' is not a subtype of type 'Null'
  return map;
}