map2<T, U, V> function

Iterable<V> map2<T, U, V>(
  1. Iterable<T> ts,
  2. Iterable<U> us,
  3. V func(
    1. T t,
    2. U u
    )
)

A map function that takes in 2 iterables. The Iterables must be of equal length.

Implementation

Iterable<V> map2<T, U, V>(
    Iterable<T> ts, Iterable<U> us, V Function(T t, U u) func) sync* {
  final Iterator<T> itt = ts.iterator;
  final Iterator<U> itu = us.iterator;
  while (itu.moveNext() && itt.moveNext()) {
    yield func(itt.current, itu.current);
  }
  if (itu.moveNext() || itt.moveNext()) {
    throw ArgumentError("Iterables aren't of equal length.");
  }
}