zipTwoLists<A, B> function

Iterable<ZippedContent<A, B>> zipTwoLists<A, B>(
  1. List<A> firstList,
  2. List<B> secondList
)

Creates a lazy iterable zipping the two lists.

For example,

  List<int> numbersAsInt = [0, 1, 2, 3, 4];
  List<String> numbersAsString = ['zero', 'one', 'two', 'three', 'four'];
  List<ZippedContent<int, String>> zipped = zipTwoLists(numbersAsInt, numbersAsString).toList();
  print(zipped); // [(0, 'zero'), (1, 'one'), (2, 'two'), (3, 'three')]
  print(zipped[2].first); // 2
  print(zipped[1].second); // one

Implementation

Iterable<ZippedContent<A, B>> zipTwoLists<A, B>(
    List<A> firstList, List<B> secondList) {
  if (firstList.length == secondList.length) {
    return _ZippedContentIterable(firstList, secondList);
  } else {
    throw StateError('The length of the two lists isn\'t the same!');
  }
}