zip3
Three iterables walked side by side — zip with one more input.
Lecture
zip3 is zip with a third
iterable. Everything the zip page
explains holds unchanged — one record per step, laziness, and stopping
the moment any input runs out, so the result is as long as the
shortest of the three. The element type is a Dart record
(A, B, C), so destructure it by pattern matching rather than
by index.
It exists as its own function because Dart has no variadic generics: a
single zip taking a list of iterables would have to erase
the per-input types, and (A, B, C) is exactly what makes the
result worth having. The same reason tee
is joined by tee3.
Both zip and zip3 have chain methods
(fx(a).zip(b), fx(a).zip3(b, c)); the chain
carries the receiver as the first input. The demo calls the top-level
fxZip3 and wraps the result in fx() to carry
on. fxZip3Async is the async form,
and like fxZipAsync it issues all three next()
calls before awaiting any of them, so the sources are pulled in parallel
per record rather than one after another.
Demo · Three inputs, one record per step
zip — the two-iterable form, and the full explanation ·
fxZipWith — combine instead of pairing ·
fxTranspose — any number of iterables, at the cost of a shared element type