toMapE<TKey, TValue> method
Converts the enumerable to a Dart Map
.
Iterates over the entire enumerable, generating keys with the
keySelector
function and values with the valueSelector
function then
saving each generated value in a Map
under the generated key.
If a duplicate key is produced, the value generated by a prior element is
overwritten. As such, the length of the resulting Map
is not guaranteed
to be the same length as the enumerable.
Implementation
Map<TKey, TValue> toMapE<TKey, TValue>(
Selector<T, TKey> keySelector, Selector<T, TValue> valueSelector) {
ArgumentError.checkNotNull(keySelector);
ArgumentError.checkNotNull(valueSelector);
final map = <TKey, TValue>{};
final iterator = this.iterator;
TKey key;
TValue value;
while (iterator.moveNext()) {
key = keySelector(iterator.current);
value = valueSelector(iterator.current);
if (map.containsKey(key)) throw KeyExistsError(key);
map[key] = value;
}
return map;
}