Deltas between ticks
Requirement
From seven price ticks, print the six deltas: each
tick next to its predecessor with the signed change to two decimal
places (a flat tick prints +0.00). The data is in the
code; both versions must print the lines shown under
Expected output.
Expected output
101.20 -> 101.65 +0.45 101.65 -> 101.40 -0.25 101.40 -> 102.10 +0.70 102.10 -> 102.10 +0.00 102.10 -> 101.85 -0.25 101.85 -> 102.30 +0.45
Side by side
RxDart
FxDart
Why they differ
They don't, by design: pairwise is one of the operators
FxDart ported from Rx, because "each value with the one
before it" is just as natural whether values are pushed or pulled.
Both sides keep one value of state, emit nothing for the first tick,
and produce n − 1 pairs. The verdict is a tie and the
interesting part is the small typing difference in what a "pair" is.
RxDart's pairwise emits a two-element
List<double> — p.first and
p.last are honest but the length-2 invariant lives in
documentation, not in the type. FxDart's emits a Dart record
(double, double): p.$1 and p.$2
are the only fields there are, and the compiler knows it. That is a
language-era artifact more than a model difference — records did not
exist when RxDart's API froze — but it is representative of the pull
library's habit of pushing invariants into types. On the model
itself: nothing to choose between them here.
Benchmark
N = 100
Time Tie
Peak memory Tie
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.