Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Function [other Function type actions]
List [operators of similar scope]
Data manipulation [other Data manipulation operators]
Set [about Set data type]
v5.10.2
Baseline
As at baseline
list.intersect(aSet)
This calculates the intersection of two List- or Set-type lists, the chained list and the Set in the aSet argument. The .intersect() test is generally intended for use with Set-type data but will work with Lists, though the output result is always Set-type, even if then passed to be stored in a List:
$MySet = $MySetA.intersect($MySetB);
$MySet = $MyList1.intersect($MyList2);
The result is a Set of all items in both $MySetA and $MySetB, or in the second example in both $MyList1 and $MyList2. As the result is always a set, any source list items are de-duped in the output.
Non-intersect
No special code is needed to find items in one set but not the other:
$MySetC = $MySetA - $MySetB; gives items only in $MySetA
$MySetC = $MySetB - $MySetA; gives items only in $MySetB
Use with Lists
Subtracting a Set from a List results in only one instance of each Set item being removed. Subtracting a List from a List each instance of a value in the second list is removed so multiple source List entries may be removed.
See also—notes linking to here: