#cp.collect.Set

An implementation of a logical set, which contains a single unique reference of each item in it. For example:

Set(1,2,2,3) == Set(1,1,2,3,3) == Set(1,2,3)

You can combine sets in a couple of ways. For example, a union:

Set(1,2):union(Set(2,3)) == Set(1,2,3) Set(1,2) | Set(2,3) == Set(1,2,3)

...or an intersection:

Set(1,2):intersection(Set(2,3)) == Set(2) Set(1,2) & Set(2,3) == Set(2)

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:

a + b | c ~= a + (b | c)

#API Overview

Constants - Useful values which cannot be changed

Functions - API calls offered directly by the extension

Constructors - API calls which return an object, typically one that offers API methods

Methods - API calls which can only be made on an object returned by a constructor


#API Documentation

#Constants

Signaturecp.collect.Set.everything <cp.collect.Set>
TypeConstant
DescriptionA Set which contains the whole universe.
NotesNone
Sourcesrc/extensions/cp/collect/Set.lua line 694

Signaturecp.collect.Set.nothing <cp.collect.Set>
TypeConstant
DescriptionAn empty Set.
NotesNone
Sourcesrc/extensions/cp/collect/Set.lua line 689

#Functions

Signaturecp.collect.Set.complement(set) -> cp.collect.Set
TypeFunction
DescriptionReturns a Set which is the complement of the provided set.
Parameters
  • set - The Set to complement.
Returns
  • The new Set.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 455

Signaturecp.collect.Set.difference(left, right) -> cp.collect.Set
TypeFunction
DescriptionReturns 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 392

Signaturecp.collect.Set.has(set, value) -> boolean
TypeFunction
DescriptionChecks 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 310

Signaturecp.collect.Set.intersection(left, right) -> cp.collect.Set
TypeFunction
Description
Parameters
  • left - The left Set
  • right - The right Set.
Returns
  • A new Set which contains an intersection left and right.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 360

Signaturecp.collect.Set.is(thing) -> boolean
TypeFunction
DescriptionChecks if the thing is a Set.
Parameters
  • thing - The thing to check.
Returns
  • true if it is a Set.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 213

Signaturecp.collect.Set.isComplement(set) -> boolean
TypeFunction
DescriptionChecks if the set is a complement set.
Parameters
  • set - The set to check.
Returns
  • true if the set is a complement.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 496

Signaturecp.collect.Set.size(set) -> number
TypeFunction
DescriptionReturns 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 476

Signaturecp.collect.Set.symetricDifference(left, right) -> cp.collect.Set
TypeFunction
DescriptionPerforms a symetric difference of keys with a value of true in the left and right table into a new table. The resulting table will contain items that only occur in the left or right set, but not both.
Parameters
  • left - The left Set.
  • right - The right Set.
Returns
  • The new Set.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 425

Signaturecp.collect.Set.union(left, right) -> cp.collect.Set
TypeFunction
DescriptionReturns 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 324

#Constructors

Signaturecp.collect.Set.clone(set) -> cp.collect.Set
TypeConstructor
DescriptionCreates a new Set which is a clone of the provided Set.
Parameters
  • set - The set to clone.
Returns
  • The new Set instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 292

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | 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. Any duplicate items will only occur in the Set once. | | Parameters |

  • list - The table that contains items as a list to add to the Set. E.g. {"foo", "bar"}</li></ul> | | **Returns** | <ul><li>The new Set`.
| | Notes | None | | Examples | None | | Source | src/extensions/cp/collect/Set.lua line 244 |


Signaturecp.collect.Set.fromMap(map) -> cp.collect.Set
TypeConstructor
DescriptionCreates a new Set instance, containing the items in the provided table who's key value is true. Keys with values other than true will be ignored.
Parameters
  • map - The table that contains key/value items to add to the set. E.g. {foo = true, bar = true}
Returns
  • The new Set.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 268

Signaturecp.collect.Set.of(...) -> cp.collect.Set
TypeConstructor
DescriptionCreates a new Set instance, containing the items in the parameter list.
Parameters
  • The set items.
Returns
  • The new Set instance.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 231

#Methods

Signaturecp.collect.Set:complement() -> cp.collect.Set
TypeMethod
DescriptionReturns 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 567

Signaturecp.collect.Set:difference(right) -> cp.collect.Set
TypeMethod
DescriptionReturns 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 553

Signaturecp.collect.Set:has(value) -> boolean
TypeMethod
DescriptionChecks 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 511

Signaturecp.collect.Set:intersection(...) -> cp.collect.Set
TypeMethod
DescriptionCreates 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 539

Signaturecp.collect.Set:isComplement() -> boolean
TypeMethod
DescriptionChecks if the set is a complement set.
Parameters
  • None
Returns
  • true if the set is a complement.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 595

Signaturecp.collect.Set:size() -> number
TypeMethod
DescriptionReturns the size of the Set. 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.
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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 606

Signaturecp.collect.Set:symetricDifference(right) -> cp.collect.Set
TypeMethod
DescriptionPerforms a symetric difference of keys with a value of true in the left and right table into a new table. The resulting table will contain items that only occur in the left or right set, but not both.
Parameters
  • right - The right Set.
Returns
  • The new Set.
Notes
  • You can also use the ~ operator. E.g. a ~ b.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 581

Signaturecp.collect.Set:union(...) -> cp.collect.Set
TypeMethod
DescriptionCreates 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Set.lua line 525