Link Search Menu Expand Document

Sets

Table of contents

  1. Sets
    1. set.toString()
    2. set.toBool()
    3. set.len()
    4. set.add(value)
    5. set.contains(value)
    6. set.remove(value)

Sets

Sets are an unordered collection of unique hashable values. Set values must be of type string, number, boolean or nil.

var mySet = set("test", 10);
print(mySet); // {10, "test"}

set.toString()

Converts a given set to a string.

var set_a = set();

set_a.add("one");
set_a.add("two");

var set_b = set();
set_b.add(1);
set_b.add(2);

set_a.toString(); // '{"two", "one"}');
set_b.toString(); // '{2, 1}'

set.toBool()

Converts a set to a boolean. A set is a “truthy” value when it has a length greater than 0.

var x = set();

x.toBool(); // false
x.add("test");
x.toBool(); // true

set.len()

Returns the length of the given set.

var mySet = set();
mySet.add("Dictu!");
mySet.len(); // 1

set.add(value)

Adding to sets is just a case of passing a value to .add()

var mySet = set();
mySet.add("Dictu!");

set.contains(value)

To check if a set contains a value use .contains()

var mySet = set();
mySet.add("Dictu!");
print(mySet.contains("Dictu!")); // true
print(mySet.contains("Other!")); // false

set.remove(value)

To remove a value from a set use .remove().

Note: If you try to remove a value that does not exist a runtime error is raised, use together with .contains().

var mySet = set();
mySet.add("Dictu!");
mySet.remove("Dictu!");

This site uses Just The Docs, with modifications.