Report only status changes
Requirement
A health-check feed reports ok, ok, warn, warn, ok, ok, ok
— mostly repetition. Print one status now line per
run (three lines), then a single
statuses seen: line listing every distinct status in
first-seen order. The data is in the code; both
versions must print the lines shown under Expected output.
Expected output
status now: ok status now: warn status now: ok statuses seen: ok, warn
Side by side
RxDart
FxDart
Why they differ
Adjacent deduplication — "tell me when the value changes" —
is one value of remembered state in either model, and the two sides
are line-for-line twins. The only trap is naming, and it cuts in
opposite directions. On the stream side, plain
Stream.distinct is already adjacent-only —
RxDart adds distinctUnique for the global version many
people expect distinct to be. FxDart names it the other
way around: uniq is global, like every collection
library's uniq, and uniqAdjacent says the
adjacent-ness out loud.
Both pairs are shown above on purpose: run-collapsing with
distinct / uniqAdjacent, the
seen-anywhere summary with
distinctUnique / uniq. Note what
the global versions cost in each model — a growing "seen" set either
way, but the stream one must hold it for the (potentially unbounded)
life of a subscription, which is why RxDart makes the global form
the opt-in. On a finite feed like this the models don't separate at
all: a tie.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 1,000,000
Time FxDart wins
Peak memory RxDart 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.