Stof Docs
Star on GitHubStof WebsiteDiscordContact Us
  • 🚀Welcome
  • â„šī¸Resources & Information
  • Book
    • Data Interface
    • Introduction & Design
    • Host Environments
      • Rust
      • TypeScript
        • Extend Stof
        • Import Statement
    • Data Interchange
      • JSON to Stof
      • Importing and Parsing Data
      • Exporting Data
      • REST and Restructure
    • Configuration Files
    • Schemas
      • Renaming Fields
      • Removing Fields
      • Validation & Transformation
        • Example Access
      • Nested Schemas
    • Orchestration
  • Common Concepts
    • Objects
    • Primitive Types
    • Functions
    • Fields
    • Object Types
    • Imports
    • Error Handling
    • Units
    • Casting/Conversions
  • Reference
    • CLI
      • 🏃Run
      • đŸ§ĒTest
      • 📚CLI Libraries
        • Filesystem Library
        • Time Library
        • HTTP Library
    • Stof Language
    • Libraries
      • Standard Library
      • Array/Vector Library
      • Number Library
      • String Library
      • Object Library
      • Function Library
      • Set Library
      • Map Library
      • Data Library
      • Tuple Library
      • Blob Library
      • Boolean Library
    • đŸĒ§Formats
Powered by GitBook
On this page
  • Common Value Functions
  • Tuple.toString(tup: (.., ..)): str
  • Tuple.or(tup: (.., ..), ...): unknown
  • Tuple Functions
  • Tuple.len(tup: (.., ..)): int
  • Tuple.at(tup: (.., ..), index: int): unknown

Was this helpful?

  1. Reference
  2. Libraries

Tuple Library

Stof's standard tuple library ("Tuple").

PreviousData LibraryNextBlob Library

Last updated 4 months ago

Was this helpful?

Tuples can be cast to vectors for more available operations.

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 "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
}
Standard Library