isSubsetOf method

bool isSubsetOf(
  1. Set<Object?> other
)

Utility extension methods for working with sets in Dart.

Provides helpful methods for checking subset and superset relationships between sets, particularly when working with sets of nullable objects.

Example:

final a = {1, 2};
final b = {1, 2, 3};
print(a.isSubsetOf(b)); // true
print(b.isSupersetOf(a)); // true

Returns true if this set is a subset of other, meaning all elements in this set also exist in other. If this set has more elements than other, it immediately returns false as an optimization.

Example:

final a = {'x'};
final b = {'x', 'y'};
print(a.isSubsetOf(b)); // true

Implementation

bool isSubsetOf(Set<Object?> other) {
  if (length > other.length) return false;
  for (final element in this) {
    if (!other.contains(element)) return false;
  }
  return true;
}