contains
Returns true when an iterable contains a value, compared with ==.
Lecture
contains is the Dart-idiomatic name for membership testing,
and on a chain you already have it: Fx inherits
.contains() from Iterable, so
fx(xs).contains(a) just works. There is no top-level
contains function, though — the name collides with
package:test's matcher — so the data-first form keeps its
FxTS spelling includes(a, iterable), which is literally
iterable.contains(a). The async
version, includesAsync, is built on top of
someAsync (b == a as
the predicate), which means it inherits the same short-circuiting: it
stops pulling from the source the moment it finds a match.
Equality is checked with Dart's ==, so it respects any
operator == override on your own classes — it isn't limited
to primitives.
Demo 1 · Basics
Demo 2 · Async, and proof it short-circuits
Only 2 of 5 elements are pulled before includesAsync stops:
Try it yourself
Exercise: use contains to check whether requestId is allowed.