This site has been deprecated. Do not edit pages here. Please visit the new Pico Labs documentation.


Skip to end of metadata
Go to start of metadata

Set operators are common set operations that makes working with arrays easier.  All set operations return an array except for has which returns a boolean value.  The following operations are possible with sets:

Given arrays (sets) A and B:

intersection (A ∩ B):

 The set of all objects that are a member of both A and B

Usage:

Union (A ∪ B):

 The set of all objects that are a member of A or B (or both)

Usage:

difference (A \ B):

 The set of all members of A that are not members of B

Usage:

has (B ⊆ A):

 B is a subset of A (or it could be read as A is a superset of B)

Usage:

once:

 Set of elements e that only appear 1 time in A

Usage:

duplicates:

 Set of elements e that appear more than once in A

Usage:

unique:

 Set of (unique) elements e belonging to A

Usage:

Example

Set operators like other KRL operators can chained to perform more complex operations. This is how you could make your own symmetric difference operation (set of elements e belonging to either A or B, but not both):

Labels: