omitBy

Returns a copy of a Map without the entries matching a predicate.

Map<K, V> omitBy<K, V>(bool Function((K, V) entry) f, Map<K, V> map)

Lecture

Where omit takes a fixed list of keys, omitBy takes a predicate and decides entry by entry. The predicate receives the whole entry as a (K, V) record, so you get both the key and the value to work with — read them as e.$1 (key) and e.$2 (value). This mirrors how entries(map) represents a Map throughout the rest of the library.

Use it whenever the thing you want to drop is defined by a condition — "remove failing scores," "remove out-of-stock items" — rather than by a fixed set of key names.

Demo 1 · Basics

Demo 2 · Dropping by value condition

Try it yourself

Exercise: use omitBy to drop entries whose value is false.

Related: pickBy — the inverse: keep by predicate · omit — drop by a fixed key list · isMatch — a ready-made deep predicate for entries · evolve — transform values instead of dropping them