associateWith<V> method

Map<E, V> associateWith<V>(
  1. V valueSelector(
    1. E element
    )
)

Returns a Map containing the values returned from valueSelector function applied to each element indexed by the elements from the collection.

If any of elements (-> keys) would be the same the last one gets added to the map.

Implementation

Map<E, V> associateWith<V>(V Function(E element) valueSelector) {
  var map = <E, V>{};
  for (var current in this) {
    map[current] = valueSelector(current);
  }
  return map;
}