Sets

Operators and functions for working with an array of boolean values (set type) are described here.

Operators

Functions

arr(set s) arr.int

The arr function converts a set value to an array of integers that contains indexes of set items.

set(str s) set

The set function converts a string to a set value and returns it. The string must only have 1 and 0 characters.

set(arr.int a) set

The set function converts an array of integers to a set value and returns it. The result set will have items with corresponding indexes.

run arr.int {
  set s &= {780, 99, 128, 105, 136}
  arr.int as = arr(s)
  as += 330
  s &= set(as)
  return arr(s) // [99 105 128 136 330 780]
}

str(set s) str

The str function converts a set value to a string and returns it. The result string contains only 1 and 0.

Set(set s, int index) set

The Set function adds an index item to the set. It is the same as s[index] = true. The function returns s.

Toggle(set s, int index) bool

The Toggle function adds an index item to the set if the set doesn't have it and otherwise, the function removes the item. It is the same as s[index] = !s[index]. The function returns the previous state - true if the item existed and, otherwise, false.

UnSet(set s, int index) set

The UnSet function removes an index item from the set. It is the same as s[index] = false. The function returns s.

Last updated