whereKey method

Map<K, V> whereKey(
  1. bool f(
    1. K key
    )
)

Filters the map by its keys using the provided predicate function. The function f takes a key as a parameter and returns a boolean indicating whether the key 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> filteredByKey = scores.whereKey((key) => key.length == 3);
  print(filteredByKey); // Output: {Bob: 75, Eve: 85}
}

Implementation

Map<K, V> whereKey(bool Function(K key) f) => {...where((key, value) => f(key))};