associate<K, V> method

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

Associates each element of this iterable into a Map by applying transform to produce a MapEntry.

['alice', 'bob'].associate((s) => MapEntry(s, s.length));
// {'alice': 5, 'bob': 3}

Implementation

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