diffAndIntersect<G> method
Given this set and other, returns:
- Items of this set which are NOT in
other(difference this - other), in this set"s order. - Items of
otherwhich are NOT in this set (difference other - this), inother"s order. - Items of this set which are also in
other, in this set"s order. - Items of this set which are also in
other, inother"s order.
Implementation
DiffAndIntersectResult<T, G> diffAndIntersect<G>(
Set<G> other, {
bool diffThisMinusOther = true,
bool diffOtherMinusThis = true,
bool intersectThisWithOther = true,
bool intersectOtherWithThis = true,
}) {
final List<T>? _diffThisMinusOther = diffThisMinusOther ? [] : null;
final List<G>? _diffOtherMinusThis = diffOtherMinusThis ? [] : null;
final List<T>? _intersectThisWithOther = intersectThisWithOther ? [] : null;
final List<T>? _intersectOtherWithThis = intersectOtherWithThis ? [] : null;
if (diffThisMinusOther || intersectThisWithOther)
for (final element in this) {
if (other.contains(element)) {
_intersectThisWithOther?.add(element);
} else
_diffThisMinusOther?.add(element);
}
if (diffOtherMinusThis || intersectOtherWithThis)
for (final element in other) {
if (contains(element))
_intersectOtherWithThis?.add(element as T);
else
_diffOtherMinusThis?.add(element);
}
return DiffAndIntersectResult(
diffThisMinusOther: _diffThisMinusOther,
diffOtherMinusThis: _diffOtherMinusThis,
intersectThisWithOther: _intersectThisWithOther,
intersectOtherWithThis: _intersectOtherWithThis,
);
}