containsAll method

bool containsAll(
  1. Iterable<T> other, {
  2. bool equals(
    1. Object?,
    2. Object?
    ) = _equalityTest,
})

Returns whether other's elements are all included in this collection.

Equality of elements is implemented by == test by default for equals.

Note that duplicate elements in other are not considered:

[1, 2, 3].containsAll([2, 3, 3]) // true

IMPORTANT: This function is intentionally generic over performant; when other's size grows to a non-trivial size, it is recommended to roll your own implementation based on the semantics of your collections.

Implementation

bool containsAll(
  Iterable<T> other, {
  bool Function(Object?, Object?) equals = _equalityTest,
}) {
  if (identical(this, other)) {
    return true;
  }
  for (final element in other) {
    if (!contains(element)) {
      return false;
    }
  }
  return true;
}