Flatten orders into lines
Requirement
Yesterday's four orders each hold two or three line items. Flatten
them into one list of order/sku lines — every item under
its order id, in source order — and print the line count. The data is
in the code; both versions must print the lines shown under
Expected output.
Expected output
A-101/tea-01 A-101/mug-07 A-102/pen-11 A-102/ink-02 A-102/pad-05 A-103/mug-07 A-103/lid-04 A-104/tea-01 A-104/jar-03 A-104/lid-04 10 lines from 4 orders
Side by side
RxDart
FxDart
Why they differ
One-to-many flattening is bedrock in both models, and for a
synchronous payload the two spellings are the same word:
Stream.expand and FxDart's flatMap both
take element to iterable, splice the pieces in source
order, and hand the result to a formatting map. The
panels are line-for-line parallel.
The interesting divergence is just offstage. When each order's lines
arrived asynchronously, the Rx side would graduate to
RxDart's flatMapIterable or flatMap —
inner streams, where merge order becomes a real question
(interleaving by completion unless you concatenate). FxDart's
async flatMap on a pulled pipeline stays in source
order by construction. But that is a tier-4 story; on this in-memory
job both sides express the flatten directly — the Rx panel doesn't
even need an RxDart operator, core Stream carries it —
and the only trace is the async main. A tie.
Benchmark
N = 100
Time Tie
Peak memory RxDart wins
N = 1,000,000
Time FxDart wins
Peak memory Tie
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.