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

zipWith

Zips two iterables and combines each pair through a function, in one step.

Iterable<C> zipWith<A, B, C>(C Function(A a, B b) f, Iterable<A> iterable1, Iterable<B> iterable2) FxAsyncIterable<C> zipWithAsync<A, B, C>(FutureOr<C> Function(A a, B b) f, FxAsyncIterable<A> iterable1, FxAsyncIterable<B> iterable2)

Lecture

zipWith is exactly zip followed by map over the resulting pairs — in fact that's how it's implemented in FxDart, as map((r) => f(r.$1, r.$2), zip(...)). Reach for it when you don't actually want the intermediate (A, B) record, just the combined result: multiplying two parallel lists together, formatting a name and an age into one label, and so on.

It stops at the shorter of the two inputs, same as zip, and the async form zipWithAsync inherits zipAsync's parallel-per-pair pulling. There's no Fx chain form for zipWith — call the top-level function directly (or build it yourself as .zip(other).map((r) => f(r.$1, r.$2))).

Demo 1 · Basics

Demo 2 · Async

Try it yourself

Exercise: use zipWith to compute the line total (price * quantity) per pair.

Related: zip — the plain-pairs version this builds on · zipWithIndex — zip against a running index · map