min
The smallest number in the pipeline — with FxTS's exact quirks on empty and NaN input.
num min(Iterable<num> iterable)
Future<num> minAsync(FxAsyncIterable<num> iterable)
num Fx<num>.min() // chain (sync)
Future<num> FxAsync<num>.min() // chain (async)
Lecture
min is a terminal, numeric-only fold — internally it's
fold(double.infinity, ..., iterable), comparing each element
against a running minimum that starts at +infinity.
Two behaviors are worth memorizing, because they surprise people coming from a "safe" API and are ported faithfully from FxTS:
-
An empty iterable returns
double.infinity— notnull, not an error. That's simply what the fold seed is when nothing ever beats it. -
A single
NaNanywhere in the iterable poisons the whole result toNaN— every comparison againstNaNis false, so once it's the running minimum (or shows up as a candidate), it staysNaNforever.
If you need "smallest, or null if empty" semantics instead,
check result.isInfinite yourself, or reach for
find /
reduce with your own comparator.
Demo 1 · Basics, empty, and NaN
Demo 2 · Async
Try it yourself
Exercise: find the cheapest price among the products.