startsWith method

bool startsWith(
  1. Iterable<T> other,
  2. {bool comparer(
    1. T otherElement,
    2. T element
    )?}
)

Returns true if this iterable starts with the same elements that are in other.

Implementation

bool startsWith(
  Iterable<T> other, {
  bool Function(T otherElement, T element)? comparer,
}) {
  comparer ??= EqualityComparer.forType<T>().compare;

  final iterator = this.iterator;

  for (var o in other) {
    if (!iterator.moveNext()) {
      return false;
    }
    if (!comparer(o, iterator.current)) {
      return false;
    }
  }

  return true;
}