fromIterable<K, V, I> static method

IMapOfSets<K, V> fromIterable<K, V, I>(
  1. Iterable<I> iterable, {
  2. K keyMapper(
    1. I
    )?,
  3. V valueMapper(
    1. I
    )?,
  4. bool ignore(
    1. I
    )?,
  5. ConfigMapOfSets? config,
})

Creates a map of sets instance in which the keys and values are computed from the iterable.

For each element of the iterable it computes a key/value pair, by applying keyMapper and valueMapper respectively. When the key is new, it will be created with a set containing the value. When the key already exists, each following value will be added to the existing set.

If keyMapper and valueMapper are not specified, the default is the identity function.

If ignore is provided and return true, the entry will not be included.

Implementation

static IMapOfSets<K, V> fromIterable<K, V, I>(
  Iterable<I> iterable, {
  K Function(I)? keyMapper,
  V Function(I)? valueMapper,
  bool Function(I)? ignore,
  ConfigMapOfSets? config,
}) {
  Map<K, Set<V>> map = _mutableMapOfSets<K, V, I>(
    iterable,
    keyMapper: keyMapper,
    valueMapper: valueMapper,
    ignore: ignore,
  );
  return IMapOfSets.withConfig(map, config ?? defaultConfig);
}