where
Returns a lazy iterable of the elements a predicate returns true for.
Lecture
where is the other fundamental transformer alongside
map: it keeps every element for which the predicate
returns true and drops the rest, lazily. Nothing runs
until a terminal operator pulls values through. where is
the Dart-idiomatic name; fxdart also accepts the FxTS spelling
filter — they're the same operator.
Because it's lazy, combining where with take
only evaluates as many predicate calls as needed to satisfy the
take — see Demo 1.
whereAsync has its own dedicated concurrent implementation
(rather than reusing mapAsync's): when you attach
.concurrent(n), n predicates are evaluated in
parallel, but the elements that pass are still released downstream in
their original order — concurrency changes throughput, never the
result.
Demo 1 · Basics & laziness
Demo 2 · Async, with concurrency
Try it yourself
Exercise: use where to keep only ages 18 and over.
reject — the opposite of filter ·
compact — filter out nulls ·
map — transform instead of keep/drop ·
concurrent — parallel evaluation