where method

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

Returns a new Map containing all entries that satisfy test.

The new Map preserves the entry iteration order of the this Map.

Implementation

Map<K, V> where(bool Function(K key, V value) test) {
  final result = <K, V>{};

  for (final MapEntry(:key, :value) in entries) {
    if (!test(key, value)) continue;
    result[key] = value;
  }

  return result;
}