where method

  1. @useResult
Map<K, V> where(
  1. bool predicate(
    1. K key,
    2. V value
    )
)

Eagerly returns a map with only entries that satisfy the given predicate.

final foo = {'a': 1, 'b': 2, 'c': 3};
final bar = foo.where((k, v) => k == 'a' || v == 2); // {'a': 1, 'b': 2}

Implementation

@useResult Map<K, V> where(bool Function(K key, V value) predicate) => {
  for (final MapEntry(:key, :value) in entries)
    if (predicate(key, value))
      key: value,
};