Total the valid even amounts
Requirement
A statement import produced a list of parsed amounts where two lines
failed to parse (null). Drop the failures, keep the
even amounts, and print their total. The data is in
the code; both versions must print the line shown under
Expected output.
Expected output
Even total: 202
Side by side
RxDart
FxDart
Why they differ
The pipelines are almost word-for-word the same —
whereNotNull → where → fold against
compact → filter → sum. What differs is everything
around them. The RxDart side must lift a plain list into a
Stream, go async, and await a fold, because
a stream only yields values over turns of the event loop — even when
every value is already sitting in memory. The FxDart side stays a
synchronous expression: pull values, sum, done.
That is the recurring theme of this Part: for data that is
finite and already here, a stream adds a delivery mechanism
the problem never asked for. RxDart's operator vocabulary is good —
whereNotNull is exactly compact — but the
model underneath charges an async tax on every fixed-data task. Here
the entire answer is one number, so the ceremony — the lift, the
async main, the awaited fold — is the whole difference between the
two programs; that is what carries the verdict on this page, where
later pairs with the same residue settle for a tie. The verdict
flips in Part 4, where values genuinely arrive over time and that
same machinery becomes the point.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 1,000,000
Time FxDart wins
Peak memory FxDart wins
Bars are medians of repeated timed iterations in fresh processes per side (small N is batched for timer resolution). Sides within 5% of each other — or within 0.6 ms, a difference no person can perceive — count as a tie; close relative races are re-measured up to 5 runs. In an app, anything under a few milliseconds is invisible to the user regardless of which bar is shorter. Memory is peak process RSS. The Dart VM and the dataset are identical on both sides, so the difference between the two bars is what the pipeline itself holds onto.