associate<K, V> method

Map<K, V> associate<K, V>(
  1. Pair<K, V> transform(
    1. String value
    )
)

Returns a Map containing key-value pairs that are provided by transform.

If any of the returned Pairs would contain the same key, the last one gets added to the map.

The iteration order of the string is preserved.

final string = 'bonne journée';
// Associate each character with its code.
final result = string.associate((char) => Pair(char, char.codeUnitAt(0)));

// Notice each letter occurs only once.
print(result); // {b: 98, o: 111, n: 110, e: 101,  : 32, j: 106, u: 117, r: 114, é: 233}

Implementation

Map<K, V> associate<K, V>(Pair<K, V> Function(String value) transform) {
  return split('').associate(transform);
}