associate<K, V> method

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

Returns a Map containing key-value pairs provided by transform function applied to elements of this collection.

If any of two pairs would have the same key the last one gets added to the map.

Implementation

Map<K, V> associate<K, V>(MapEntry<K, V> Function(E element) transform) {
  var map = <K, V>{};
  for (var element in this) {
    var entry = transform(element);
    map[entry.key] = entry.value;
  }
  return map;
}