associateByTo<K> method

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

生成一个Map映射,其中每个 element 都与 keySelector 函数生成键相关联,然后追加到 destination中并返回。

举例:

final map = {0: '0'};
['a', 'ab', 'abc'].associateBy(map, (e) => e.length); // {0: '0', 1: 'a', 2: 'ab', 3: 'abc'}

Implementation

Map<K, E> associateByTo<K>(Map<K, E> destination, K Function(E element) keySelector) {
  final temp = associateBy(keySelector);
  destination.addAll(temp);
  return destination;
}