associate<K, V> method

Map<K, V> associate<K, V>(
  1. MapEntry<K, V> transform(
    1. T element
    )
)

Returns a map that contains MapEntrys provided by a transform function.

If two elements share the same key, the last one gets added to the map.

Example:

[1, 2, 3].associate((e) => MapEntry('key_$e', e * 100)); // {'key_1': 100, 'key_2': 200, 'key_3': 300}

Implementation

Map<K, V> associate<K, V>(MapEntry<K, V> Function(T element) transform) {
  ArgumentError.checkNotNull(transform, 'transform');
  return Map.fromEntries(map(transform));
}