SortedMap<K extends Comparable, V>.fromIterables constructor
SortedMap<K extends Comparable, V>.fromIterables (])
Creates a SortedMap associating the given keys
to values
.
This constructor iterates over keys
and values
and maps each element of
keys
to the corresponding element of values
.
If keys
contains the same object multiple times, the last occurrence
overwrites the previous value.
It is an error if the two Iterables don't have the same length.
Implementation
factory SortedMap.fromIterables(Iterable<K> keys, Iterable<V> values,
[Ordering ordering = const Ordering.byKey()]) {
var map = SortedMap<K, V>(ordering);
var keyIterator = keys.iterator;
var valueIterator = values.iterator;
var hasNextKey = keyIterator.moveNext();
var hasNextValue = valueIterator.moveNext();
while (hasNextKey && hasNextValue) {
map[keyIterator.current] = valueIterator.current;
hasNextKey = keyIterator.moveNext();
hasNextValue = valueIterator.moveNext();
}
if (hasNextKey || hasNextValue) {
throw ArgumentError('Iterables do not have same length.');
}
return map;
}