Skip to main content

Values

These functions allow you to work with various types of values. These functions tend to be polymorphic, which means they can accept many different types of values and behave differently depending on the type of value passed in.

Contains

a.Contains(b) -> boolean

Returns true if the a contains the given b.

  • If a is an Array, returns true if b is an element of the Array.
  • If a is a Map, returns true if b is a value in the Map.
  • If a is a Range, returns true if b is a number within the Range.
  • If a is a Category, returns true if b is a subset or equal to a.
  • If a is a Flag, returns true if b is a subset or equal to a.
  • If a is a String, returns true if b is a substring of a.

In all other cases, returns false.

CountBits

x.CountBits -> number
CountBits(x) -> number

Returns the number of bits set in the input. The input must be a Flag or Category, unless it is nullish, in which case this function returns undefined.

IsEmpty

x.IsEmpty -> boolean
IsEmpty(x) -> boolean

Returns true if the value is empty, false otherwise. A value is empty if it is:

  • null or undefined
  • false
  • 0
  • @(0,0)
  • a String of length 0
  • an Array, Map or Range with no elements

Length

x.Length -> value
Length(x) -> value

Returns the length of x.

  • If x is a V2, returns the length of the vector.
  • If x is an Array, returns the number of elements.
  • If x is a Map, returns the number of key-value pairs.
  • If x is a Range, returns the number of steps in the range.
  • If x is a String, returns the number of characters. Note that this requires iterating through the string as characters are stored as UTF-8, and so the time taken for this calculation is proportional to the length of the string.
  • Otherwise, returns undefined.

OrDefault

x.OrDefault(default) -> value

Returns the first argument if it is not undefined, otherwise returns the second argument.

Overlaps

a.Overlaps(b) -> boolean

Returns true if the a and b have any elements in common.

  • If a and b are both Categories, returns true if they have any categories in common.
  • If a and b are both Flags, returns true if they have any values in common.
  • Otherwise, returns false.