zipAll<U> method

Iterable<Tuple2<T?, U?>> zipAll<U>(
  1. Iterable<U> otherIterable, {
  2. T currentFill(
    1. int index
    )?,
  3. U otherFill(
    1. int index
    )?,
})

Aggregate two sources based on the longest source. Missing elements can be completed by passing a currentFill and otherFill methods or will be at null by default

Implementation

Iterable<Tuple2<T?, U?>> zipAll<U>(
  Iterable<U> otherIterable, {
  T Function(int index)? currentFill,
  U Function(int index)? otherFill,
}) {
  final other = otherIterable.toList();
  final current = toList(growable: false);
  final maxLength = max(current.length, other.length);

  Object? getOrFill(List l, int index, Function? fill) => index < l.length
      ? l[index]
      : fill != null
          ? fill(index)
          : null;

  return Iterable.generate(
      maxLength,
      (index) => Tuple2<T?, U?>(
            getOrFill(current, index, currentFill) as T?,
            getOrFill(other, index, otherFill) as U?,
          )).toIList(config);
}