endsWith method

bool endsWith (
  1. Iterable<T> other,
  2. {bool comparer(
    1. T value,
    2. T otherValue
    )}
)

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

Implementation

bool endsWith(
  Iterable<T> other, {
  bool Function(T value, T otherValue) comparer,
}) {
  checkNullError(this);
  if (other == null) {
    throw ArgumentError.notNull('other');
  }

  comparer ??= EqualityComparer.forType<T>().compare ?? (a, b) => a == b;

  final count = other.count();
  final tail = takeLast(count);

  return tail.sequenceEquals(other, comparer: comparer);
}