combineIterables<A, B, R> function
Combines iterables a
and b
into one, by applying the combine
function.
If allowDifferentSizes
is true, it will stop as soon as one of the
iterables has no more values. If allowDifferentSizes
is false, it will
throw an error if the iterables have different length.
See also: IterableZip
Implementation
Iterable<R> combineIterables<A, B, R>(
Iterable<A> a,
Iterable<B> b,
R Function(A, B) combine, {
bool allowDifferentSizes = false,
}) sync* {
Iterator<A> iterA = a.iterator;
Iterator<B> iterB = b.iterator;
while (iterA.moveNext()) {
if (!iterB.moveNext()) {
if (allowDifferentSizes)
return;
else
throw StateError("Can't combine iterables of different sizes (a > b).");
}
yield combine(iterA.current, iterB.current);
}
if (iterB.moveNext() && !allowDifferentSizes)
throw StateError("Can't combine iterables of different sizes (a < b).");
}