retainWhere method
Retains all entries that satisfy the given predicate
.
final foo = {'a': 1, 'b': 2};
foo.retainWhere((k, v) => v < 2); // {'b': 2}
Implementation
void retainWhere(bool Function(K key, V value) predicate) {
// We remove all elements at the end to ensure atomicity.
[ for (final MapEntry(:key, :value) in entries) if (!predicate(key, value)) key ].forEach(remove);
}