このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

fxUnzip

Pairs in, two lists out — the inverse of zip, in a single pass.

(List<A>, List<B>) fxUnzip<A, B>(Iterable<(A, B)> iterable) Future<(List<A>, List<B>)> fxUnzipAsync<A, B>(FxAsyncIterable<(A, B)> iterable) (List<A>, List<B>) Fx<(A, B)>.unzip() // chain (sync) Future<(List<A>, List<B>)> FxAsync<(A, B)>.unzip() // chain (async)

Lecture

zip pairs two iterables up; fxUnzip(pairs) takes them apart again. It returns a record (lefts, rights) — two Lists, filled side by side in one walk over the input — so the usual way in is a destructuring declaration: final (names, scores) = fxUnzip(pairs);. The long-hand, two maps over the same pairs, walks the input twice.

The round trip holds up to length: fxUnzip(fxZip(a, b)) gives back a and b, truncated to the shorter of the two, because zip already dropped the rest. Empty input gives two empty lists. Unlike most of section 6, unzip is strict, and has to be: a lazy one would hand back two iterables over one source, and draining either would buffer everything the other had not reached yet (the cost fork pays).

fxUnzipAsync drains an FxAsyncIterable of pairs into a Future of the same record. On the chain it is .unzip() — an extension on Fx<(A, B)> and FxAsync<(A, B)>, so it appears only on chains of positional pairs, such as the ones zip, attach and pairwise produce. Dart-native addition (FxTS has no unzip); Kotlin and Rust spell it the same.

Demo 1 · Pairs into two lists

Demo 2 · Closing an async chain

Try it yourself

Exercise: split the points in one pass.

Related: zip — the other direction · zipWith — zip and combine in one step · partition — two lists split by a predicate · attach — builds the pairs to unzip