IMap<K, V>.fromIterables constructor

IMap<K, V>.fromIterables(
  1. Iterable<K> keys,
  2. Iterable<V> values, {
  3. ConfigMap? config,
})

Creates an IMap instance 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.

List<String> letters = ['b', 'c'];
List<String> words = ['bad', 'cat'];
IMap<String, String> map = IMap.fromIterables(letters, words);
map['b'] + map['c'];  // badcat

If keys contains the same object multiple times, the last occurrence overwrites the previous value.

The two Iterables must have the same length.

See also: fromIterable

Implementation

factory IMap.fromIterables(Iterable<K> keys, Iterable<V> values, {ConfigMap? config}) {
  Map<K, V> map = ListMap.fromIterables(keys, values, sort: (config ?? defaultConfig).sort);
  return IMap._(map, config: config ?? defaultConfig);
}