isSubset<T> function
- Eq<
T> eq
Determines if one ImmutableList is a subset of another ImmutableList using a curried function.
This function checks if all items in the first list (subsetCandidate
) are contained
in the second list (set
). It uses a custom equality comparer Eq<T> to
determine if elements are the same.
Example:
final list1 = ImmutableList([1, 2, 3]);
final list2 = ImmutableList([1, 2, 3, 4, 5]);
final intEq = Eq<int>((a, b) => a == b);
final check = isSubset(intEq)(list2);
print(check(list1)); // true
eq
: An equality comparer that checks if two items of type T
are the same.
Implementation
bool Function(ImmutableList<T> subsetCandidate) Function(ImmutableList<T> set)
isSubset<T>(Eq<T> eq) {
return (ImmutableList<T> set) {
return (ImmutableList<T> subsetCandidate) {
return every(
subsetCandidate, (x) => set.items.any((y) => eq.equals(x, y)));
};
};
}