Tinderbox 7 Icon

List/Set.intersect(set)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 List   [operators of similar scope]

 Data manipulation   [other Data manipulation operators]

 Baseline

 


Set.intersect(set)

This calculates the intersection of two List or Sets. Intersect is generally intended for Set but will work with Lists, though the result is always a Set.

$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.