pickBy
Returns a copy of a Map with only the entries matching a predicate.
Map<K, V> pickBy<K, V>(bool Function((K, V) entry) f, Map<K, V> map)
Lecture
pickBy is omitBy'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 pickBy to keep only entries whose value is true.
Related:
omitBy — the inverse: drop by predicate ·
pick — keep by a fixed key list ·
matches — a ready-made predicate for shape matching ·
compactObject — a specialized "drop nulls" pickBy