average
The mean of every number the pipeline produces — NaN when there are none.
Lecture
average is a terminal operator that walks the whole
pipeline once, tracking both a running total and a running count, then
divides. It always returns a double, even for a list of
plain ints.
The one behavior worth internalizing: average of an
empty iterable is double.nan — it's
computing 0 / 0, not throwing and not defaulting to
0. This mirrors FxTS exactly. If your pipeline might be
empty, check for that explicitly (result.isNaN) rather than
assuming a numeric fallback.
Like sum, the chain form is exposed
through a Fx<num> / FxAsync<num>
extension, so it only becomes available once the compiler can see your
chain's element type is numeric.
Demo 1 · Basics & the empty case
Demo 2 · Async
Try it yourself
Exercise: average only the passing scores (>= 60).