Available since: v3.0.0-alpha.12
These functions can be used when working with, and manipulating sets of data.
| Function | Description |
|---|---|
set::add() | Adds an item to a set if it does not exist |
set::complement() | Returns the complement of two sets |
set::contains() | Checks to see if a value is present in a set |
set::difference() | Returns the difference between two sets |
set::intersect() | Returns the values which intersect two sets |
set::is_empty() | Checks if a set is empty |
set::len() | Returns the length of a set |
set::remove() | Removes an item at a specific position from a set |
set::union() | Returns the unique merged values from two sets |
set::addThe set::add function adds an item to a set.
API DEFINITIONset::add(set, value) -> set
If the item is not present in the set, it will be added.
{"one", "two"}.add("three"); -- {'one', 'three', 'two'}
Otherwise, the original set will be returned.
{"one", "two"}.add("two"); -- {'one', 'two'}
set::complementThe set::complement function returns the complement of two sets, namely a single set containing items which are not in the second set.
API DEFINITIONset::complement(set, set) -> set
Example with output{1, 2, 3, 4}.complement({3, 4, 5, 6}); -- {1, 2}
set::containsThe set::contains function checks to see if a value is contained within a set.
API DEFINITIONset::concat(set, set) -> set
Example with output{1, 2, 3}.contains(3); -- true
set::differenceThe set::difference function determines the difference between two sets, returning a single set containing items which are not in both sets.
API DEFINITIONset::difference(set, set) -> set
Example with output{1, 2, 3, 4}.difference({3, 4, 5, 6}); -- {1, 2, 5, 6}
set::intersectThe set::intersect function calculates the values which intersect two sets, returning a single set containing the values which are in both sets.
API DEFINITIONset::intersect(set, set) -> set
Example with output{1, 2, 3, 4}.intersect({3, 4, 5, 6}); -- {3, 4}
set::is_emptyThe set::is_empty function checks whether the set is empty or not.
API DEFINITIONset::is_empty(set) -> bool
Example with output{1, 2, 3, 4}.is_empty(); -- false
set::lenThe set::len function calculates the length of a set, returning a number. This function includes all items when counting the number of items in the set. If you want to only count truthy values, then use the count() function.
API DEFINITIONset::len(set) -> number
Example with output{1, 2, 1, null, "something", 3, 3, 4, 0}.len(); -- 7
set::removeThe set::remove function removes an item of a certain value from a set.
API DEFINITIONset::remove(set, value) -> set
The following example removes the value 2 from a set.
{1, 2, 2, 2, 5}.remove(2); -- {1, 5}
If the value does not exist, the untouched set will be returned.
Removing{1, 2, 2, 2, 5}.remove(3); -- {1, 2, 5}
set::unionThe set::union function combines two sets together, removing duplicate values, and returning a single set.
API DEFINITIONset::union(set, set) -> set
Example with output{1, 2, 1, 6}.union({1, 3, 4, 5, 6}); -- {1, 2, 3, 4, 5, 6}