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
other
which 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,
}) {
List<T>? _diffThisMinusOther = diffThisMinusOther ? [] : null;
List<G>? _diffOtherMinusThis = diffOtherMinusThis ? [] : null;
List<T>? _intersectThisWithOther = intersectThisWithOther ? [] : null;
List<T>? _intersectOtherWithThis = intersectOtherWithThis ? [] : null;
if (diffThisMinusOther || intersectThisWithOther)
for (var element in this) {
if (other.contains(element)) {
_intersectThisWithOther?.add(element);
} else
_diffThisMinusOther?.add(element);
}
if (diffOtherMinusThis || intersectOtherWithThis)
for (var 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,
);
}