tuple

contains

|Tuple, Value| -> Bool

Returns true if the tuple contains a value that matches the input value.

Matching is performed with the == equality operator.

Example

(1, "hello", [99, -1]).contains "hello"
# -> true

("goodbye", 123).contains "hello"
# -> false

first

|Tuple| -> Value

Returns the first value in the tuple, or Null if the tuple is empty.

Example

x = 99, -1, 42
x.first()
# -> 99

(,).first()
# -> null

get

|Tuple, Number| -> Value
|Tuple, Number, Value| -> Value

Gets the Nth value in the tuple. If the tuple doesn't contain a value at that position then the provided default value is returned. If no default value is provided then Null is returned.

Example

x = 99, -1, 42

x.get 1
# -> -1

x.get -1
# -> null

x.get 5, "abc"
# -> abc

last

|Tuple| -> Value

Returns the last value in the tuple, or Null if the tuple is empty.

Example

x = 99, -1, 42
x.last()
# -> 42

(,).last()
# -> null

sort_copy

|Tuple| -> Tuple

Returns a sorted copy of the tuple.

Example

x = (1, -1, 99, 42)
y = x.sort_copy()
y
# -> (-1, 1, 42, 99)

x # x remains untouched
# -> (1, -1, 99, 42)

to_list

|Tuple| -> List

Returns a copy of the tuple's data as a list.

Example

(1, 2, 3).to_list()
# -> [1, 2, 3]