zipPartialWith method

Iterable<List<E>> zipPartialWith(
  1. E padding
)

Combines the first, second, third, ... elements of each Iterable into a new list. The resulting iterable has the length of the longest input iterable, missing values are padded with padding.

Implementation

Iterable<List<E>> zipPartialWith(E padding) sync* {
  if (isEmpty) {
    return;
  }
  final iterators =
      map((iterable) => iterable.iterator).toList(growable: false);
  for (;;) {
    var hasAny = false;
    final result = <E>[];
    for (final iterator in iterators) {
      if (iterator.moveNext()) {
        result.add(iterator.current);
        hasAny = true;
      } else {
        result.add(padding);
      }
    }
    if (hasAny) {
      yield result;
    } else {
      return;
    }
  }
}