startsWith method

bool startsWith(
  1. Iterable<E> other
)

Returns true if this starts with other in order.

Implementation

bool startsWith(Iterable<E> other) {
  var iterator = this.iterator;
  var otherIterator = other.iterator;

  while (true) {
    var hasElementsLeft = iterator.moveNext();
    var otherHasElementsLeft = otherIterator.moveNext();

    if (!otherHasElementsLeft) {
      return true;
    }
    if (!hasElementsLeft) {
      return false;
    }
    if (iterator.current != otherIterator.current) {
      return false;
    }
  }
}