tuple
contains
|Tuple, value: Any| -> Bool
Returns true
if the tuple contains a value that matches the input value.
Matching is performed with the ==
equality operator.
Example
.contains "hello"
#: true
.contains "hello"
#: false
first
|Tuple| -> Any?
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, index: Number| -> Any?
|Tuple, index: Number, default: Any| -> Any?
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
is_empty
|Tuple| -> Bool
Returns true
if the tuple has a size of zero, and false
otherwise.
Example
.is_empty
#: true
.is_empty
#: false
last
|Tuple| -> Any?
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.
|List, key: |Any| -> Any| -> List
Returns a sorted copy of the tuple, based on the output of calling a key
function for each of the tuple's elements.
The key function's result is cached, so it's only called once per value.
Example
x =
y = x.sort_copy
y
#: (-1, 1, 42, 99)
x # x remains untouched
#: (1, -1, 99, 42)
# Sort in reverse order by using a key function
x.sort_copy |n| -n
#: (99, 42, 1, -1)
to_list
|Tuple| -> List
Returns a copy of the tuple's data as a list.
Example
.to_list
#: [1, 2, 3]