本页尚未翻译,因此以英文显示。 参与翻译

fxOmitBy

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

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

Lecture

Where fxOmit takes a fixed list of keys, fxOmitBy 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 fxEntries(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 fxOmitBy to drop entries whose value is false.

Related: fxPickBy — the inverse: keep by predicate · fxOmit — drop by a fixed key list · fxIsMatch — a ready-made deep predicate for entries · fxEvolve — transform values instead of dropping them