where method

Map<K, V> where(
  1. bool f(
    1. K key,
    2. V value
    )
)

Filters the map by its keys and values using the provided predicate function. The function f takes a key and a value as parameters and returns a boolean indicating whether the key-value pair should be included in the resulting map.

Example usage:

void main() {
  Map<String, int> scores = {
    'John': 80,
    'Alice': 90,
    'Bob': 75,
    'Eve': 85,
  };

  Map<String, int> filteredMap = scores.where((key, value) => value >= 80);
  print(filteredMap); // Output: {John: 80, Alice: 90, Eve: 85}
}

Implementation

Map<K, V> where(bool Function(K key, V value) f) => Map<K, V>.fromEntries(
  entries.where((entry) => f(entry.key, entry.value)),
);