このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

fxPickBy

Returns a copy of a Map with only the entries matching a predicate.

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

Lecture

fxPickBy is fxOmitBy's mirror, and shares its calling convention: the predicate receives one (K, V) record per entry, so use e.$1 for the key and e.$2 for the value. Only entries where the predicate returns true survive into the result.

A common use: filtering a map of config values or feature flags down to "the ones that matter right now" — active flags, keys with a given prefix, values above a threshold — without hand-writing an entry-by-entry loop.

Demo 1 · Basics

Demo 2 · Filtering by key

Try it yourself

Exercise: use fxPickBy to keep only entries whose value is true.

Related: fxOmitBy — the inverse: drop by predicate · fxPick — keep by a fixed key list · fxMatches — a ready-made predicate for shape matching · fxCompactObject — a specialized "drop nulls" pickBy