zip2<T> function

List zip2<T>(
  1. Iterable<Iterable<T>> it,
  2. dynamic zipFunction(
    1. T a,
    2. T b
    )
)

Combine elements of two iterables into pairs and perform a function between them.

Implementation

List zip2<T>(Iterable<Iterable<T>> it, dynamic Function(T a, T b) zipFunction) {
  if (it.length != 2) {
    throw ArgumentError('Needs 2 iterables but found ${it.length}');
  }
  List result = [];

  for (var v in zipList(it)) {
    List<T> copy = List.from(v);
    result.add(zipFunction(copy[0], copy[1]));
  }

  return result;
}