Эта страница ещё не переведена, поэтому показана на английском. Помогите с переводом

zip

Pairs up elements from two iterables into records, stopping at the shorter one.

Iterable<(A, B)> zip<A, B>(Iterable<A> iterable1, Iterable<B> iterable2) Iterable<(A, B, C)> zip3<A, B, C>(Iterable<A> iterable1, Iterable<B> iterable2, Iterable<C> iterable3) FxAsyncIterable<(A, B)> zipAsync<A, B>(FxAsyncIterable<A> iterable1, FxAsyncIterable<B> iterable2) Fx<(T, U)> Fx.zip<U>(Iterable<U> other) // chain FxAsync<(T, U)> FxAsync.zip<U>(FxAsyncIterable<U> other)

Lecture

zip walks two iterables side by side and yields one pair per step, stopping the moment either input runs out. Where FxTS returns a TS tuple, FxDart returns a Dart record(A, B) — so you destructure results with .$1/.$2 or pattern matching instead of array indices. Since Dart has no variadic generics, each arity gets its own function: zip for two iterables, zip3 for three.

zipAsync issues both sides' next() calls before awaiting either — so it pulls the two sources in parallel per pair rather than sequentially. Zipping two 100ms-per-item sources still only costs ~100ms per pair, not 200ms.

Demo 1 · Basics

Demo 2 · Async, pulled in parallel per pair

Try it yourself

Exercise: zip names and ages together into (name, age) records.

Related: zipWith — zip and combine in one step · zipWithIndex — zip against a running index · transpose — zip an arbitrary number of rows · concat — chain instead of pair