Internationalisation
Bundled Plugins API
Set
An implementation of a logical set, which contains a single unique reference of each item in it. For example:
1
Set(1,2,2,3) == Set(1,1,2,3,3) == Set(1,2,3)
Copied!
You can combine sets in a couple of ways. For example, a union:
1
Set(1,2):union(Set(2,3)) == Set(1,2,3)
2
Set(1,2) | Set(2,3) == Set(1,2,3)
Copied!
...or an intersection:
1
Set(1,2):intersection(Set(2,3)) == Set(2)
2
Set(1,2) & Set(2,3) == Set(2)
Copied!
As indicated above, you can use operators for common set operations. Specifically:
Keep in mind that Lua's operator precedence may be different to that of standard set operations, so it's probably best to group operations in brackets if you combine more than one in a single statement. For example:
1
a + b | c ~= a + (b | c)
Copied!

API Overview

API Documentation

Constants

Signature
cp.collect.Set.everything <cp.collect.Set>
Type
Constant
Description
A Set which contains the whole universe.

nothing

Signature
cp.collect.Set.nothing <cp.collect.Set>
Type
Constant
Description
An empty Set.

Functions

Signature
cp.collect.Set.complement(set) -> cp.collect.Set
Type
Function
Description
Returns a Set which is the complement of the provided set.
Parameters
  • set - The Set to complement.
Returns
  • The new Set.
Signature
cp.collect.Set.difference(left, right) -> cp.collect.Set
Type
Function
Description
Returns a new Set which is the set of values in left that are not in right.
Parameters
  • left - The left Set.
  • right - The right Set.
Returns
  • The new Set.

has

Signature
cp.collect.Set.has(set, value) -> boolean
Type
Function
Description
Checks if the set has the specified value.
Parameters
  • set - The Set to check.
  • value - The value to check for.
Returns
  • true if the value is contained in the Set.
Signature
cp.collect.Set.intersection(left, right) -> cp.collect.Set
Type
Function
Description
Parameters
  • left - The left Set
  • right - The right Set.
Returns
  • A new Set which contains an intersection left and right.

is

Signature
cp.collect.Set.is(thing) -> boolean
Type
Function
Description
Checks if the thing is a Set.
Parameters
  • thing - The thing to check.
Returns
  • true if it is a Set.
Signature
cp.collect.Set.isComplement(set) -> boolean
Type
Function
Description
Checks if the set is a complement set.
Parameters
  • set - The set to check.
Returns
  • true if the set is a complement.

size

Signature
cp.collect.Set.size(set) -> number
Type
Function
Description
Returns the size of the set.
Parameters
  • set - The set to find the size of.
Returns
  • the number of values in the set, or the number of values removed from a complement set.
Notes
  • If the set is empty, 0 is returned.
  • If the set is a complement, this will return a negative number indicating how many values have been removed from the universal set of all things.
  • If the set is a complement of an empty set, nil is returned to indicate the size is infinite.
Signature
cp.collect.Set.symetricDifference(left, right) -> cp.collect.Set
Type
Function
Description
Performs a symetric difference of keys with a value of true in the left and right table into a new table.
Parameters
  • left - The left Set.
  • right - The right Set.
Returns
  • The new Set.

union

Signature
cp.collect.Set.union(left, right) -> cp.collect.Set
Type
Function
Description
Returns a new Set which is a union of the left and right
Parameters
  • left - The left Set.
  • right - The right Set.
Returns
  • A new Set which contains a union of the left and right Sets.

Constructors

clone

Signature
cp.collect.Set.clone(set) -> cp.collect.Set
Type
Constructor
Description
Creates a new Set which is a clone of the provided Set.
Parameters
  • set - The set to clone.
Returns
  • The new Set instance.

fromList

Signature
cp.collect.Set.fromList(list) -> cp.collect.Set
Type
Constructor
Description
Creates a new Set instance, containing the unique items in the table collected as a list from 1 to n.
Parameters
  • list - The table that contains items as a list to add to the Set. E.g. `{"foo", "bar"}
Returns
  • The new Set.

fromMap

Signature
cp.collect.Set.fromMap(map) -> cp.collect.Set
Type
Constructor
Description
Creates a new Set instance, containing the items in the provided table who's key value is true.
Parameters
  • map - The table that contains key/value items to add to the set. E.g. {foo = true, bar = true}
Returns
  • The new Set.

of

Signature
cp.collect.Set.of(...) -> cp.collect.Set
Type
Constructor
Description
Creates a new Set instance, containing the items in the parameter list.
Parameters
  • The set items.
Returns
  • The new Set instance.

Methods

Signature
cp.collect.Set:complement() -> cp.collect.Set
Type
Method
Description
Returns a new Set which is the complement of the current Set.
Parameters
  • None
Returns
  • The new Set.
Notes
  • You can also use the - or ~ prefix operators. E.g. -a or ~a.
Signature
cp.collect.Set:difference(right) -> cp.collect.Set
Type
Method
Description
Returns a new Set which is the set of values in this Set that are not in right.
Parameters
  • right - The right Set.
Returns
  • The new Set.
Notes
  • You can also use the - operator. E.g. a - b.

has

Signature
cp.collect.Set:has(value) -> boolean
Type
Method
Description
Checks if this set has the specified value.
Parameters
  • value - The value to check for.
Returns
  • true if the Set contains the value.
Notes
  • You can also check for specific values via mySet['key'] or mySet.key.
Signature
cp.collect.Set:intersection(...) -> cp.collect.Set
Type
Method
Description
Creates a new Set which is an intersection of the current values plus other Sets passed in.
Parameters
  • ... - The list of Sets to create an intersection from.
Returns
  • The new Set.
Notes
  • You can also use the & operator. E.g. a & b.
Signature
cp.collect.Set:isComplement() -> boolean
Type
Method
Description
Checks if the set is a complement set.
Parameters
  • None
Returns
  • true if the set is a complement.

size

Signature
cp.collect.Set:size() -> number
Type
Method
Description
Returns the size of the Set. If the set is a complement, this will return a negative number indicating
Parameters
  • None
Returns
  • the number of values in the set, or the number of values removed from a complement set.
Notes
  • If the set is empty, 0 is returned.
  • If the set is a complement, this will return a negative number indicating how many values have been removed from the universal set of all things.
  • If the set is a complement of an empty set, nil is returned to indicate the size is infinite.
Signature
cp.collect.Set:symetricDifference(right) -> cp.collect.Set
Type
Method
Description
Performs a symetric difference of keys with a value of true in the left and right table into a new table.
Parameters
  • right - The right Set.
Returns
  • The new Set.
Notes
  • You can also use the ~ operator. E.g. a ~ b.

union

Signature
cp.collect.Set:union(...) -> cp.collect.Set
Type
Method
Description
Creates a new set which is a union of the current set plus other Sets passed in.
Parameters
  • ... - The list of Sets to create a union from.
Returns
  • The new Set which is a union.
Notes
  • You can also use the | or + operator. E.g. a | b or a + b.
Last modified 1mo ago