ListMap<K, V>.fromIterables constructor

ListMap<K, V>.fromIterables(
  1. Iterable<K> keys,
  2. Iterable<V> values, {
  3. bool sort = false,
  4. int compare(
    1. K a,
    2. K b
    )?,
})

Creates a ListMap from the provided keys and values. If a key is repeated, the last occurrence overwrites the previous value.

If sort is true, it will be sorted with compare, if provided, or with compareObject if not provided. If sort is false, compare will be ignored.

The iterables keys and values must have the same number of items, otherwise it throws a StateError.

Implementation

factory ListMap.fromIterables(
  Iterable<K> keys,
  Iterable<V> values, {
  bool sort = false,
  int Function(K a, K b)? compare,
}) {
  Iterable<MapEntry<K, V>> combined =
      combineIterables(keys, values, (K key, V value) => MapEntry(key, value));

  return ListMap.fromEntries(combined, sort: sort, compare: compare);
}