BiMap<K, V>.fromIterable constructor
BiMap<K, V>.fromIterable (})
Creates a bi-map from an iterable (and optional transformation functions).
When key or value is omitted, each element is cast directly to K or
V.
Implementation
factory fromIterable(
Iterable<Object?> iterable, {
K Function(Object? element)? key,
V Function(Object? element)? value,
}) {
final result = BiMap<K, V>();
final keyProvider = key ?? (element) => element as K;
final valueProvider = value ?? (element) => element as V;
for (final element in iterable) {
result[keyProvider(element)] = valueProvider(element);
}
return result;
}