skipLast method

Iterable<E> skipLast(
  1. int count
)

Returns a new iterable containing the elements of this iterable. During iteration, the last count elements are dropped. If count is greater than the number of elements in this iterable, an empty iterable is returned.

Implementation

Iterable<E> skipLast(int count) sync* {
  final Iterator<E> iterator = this.iterator;
  final Queue<E> buffer = Queue<E>();
  while (iterator.moveNext()) {
    buffer.add(iterator.current);
    if (buffer.length > count) {
      yield buffer.removeFirst();
    }
  }
}