zipList<T> function

List<List<T>> zipList<T>(
  1. Iterable<Iterable<T>> it
)

Combine list elements into pairs

Implementation

List<List<T>> zipList<T>(Iterable<Iterable<T>> it) {
  List<List<T>> result = [];

  int minLength = 0;
  for (Iterable<T> v in it) {
    if (v.isEmpty) {
      return [];
    }

    minLength = minLength == 0 ? v.length : min(minLength, v.length);
  }

  for (int j = 0; j < minLength; j++) {
    List<T> current = [];
    for (int i = 0; i < it.length; i++) {
      current.add(List.from(it.toList()[i])[j]);
    }
    result.add(current);
  }

  return result;
}