Tuple Library
Stof's standard tuple library ("Tuple").
Common Value Functions
Tuple.toString(tup: (.., ..)): str
Returns this tuple converted to a string.
#[test('(["34", "12"])')]
fn test(): str {
return (34, 12).toString();
}
Tuple.or(tup: (.., ..), ...): unknown
Returns the first non-empty (null or void) argument, just like the Standard Library "or" function.
#[test]
fn test() {
let tup: (int, int) = self.dne.or((1, 2));
assertEq(tup, (1, 2));
}
Tuple Functions
Tuple.len(tup: (.., ..)): int
Get the number of values contained within this tuple.
#[test]
fn test() {
let tup = (12, "hello");
assertEq(tup.len(), 2);
assertEq(Tuple.len(tup), 2);
}
Tuple.at(tup: (.., ..), index: int): unknown
Get the value in this tuple at a specific index.
#[test]
fn test() {
let tup = (12, 23, 2.2, true, "hi");
assertEq(tup.at(0), 12);
assertEq(tup[2], 2.2);
for (val in tup) pln(val); // 12, 23, 2.2, true, hi
}
Last updated
Was this helpful?