interlaceWith method

Iterable<E> interlaceWith(
  1. Iterable<E> other
)

Interlaces the elements with the elements from other iterable to create an iterable with one element of each stream at the time.

If one of the iterables is bigger than the other then the remaining elements from that iterable will be added to the end.

Implementation

Iterable<E> interlaceWith(Iterable<E> other) sync* {
  final first = this.iterator;
  final second = other.iterator;
  while (first.moveNext()) {
    yield first.current;

    if (second.moveNext()) {
      yield second.current;
    }
  }

  while (second.moveNext()) {
    yield second.current;
  }
}