Skip to content

[Enhancement] Tuple type support #44

Description

@yhk1038

Overview

A feature proposal to add Tuple type support to T-Ruby.

A tuple is an array-like type with a fixed length where each position can have a different type. Implementing this with TypeScript-like syntax would significantly enhance T-Ruby's type expressiveness.

Proposed Syntax

# Basic tuple type
def get_user_info: [String, Integer]
  ["Alice", 25]
end

# Rest elements
def get_values: [String, *Integer]
  ["header", 1, 2, 3]
end

# Optional elements
def parse_result: [Boolean, String?]
  [true, nil]
end

Use Cases

  1. Multiple return values: Explicitly specify types for each value when returning multiple values from a function
  2. Structured data: Represent fixed structures like CSV rows, coordinates, key-value pairs
  3. Pattern matching: Combine with Ruby 3.0+ pattern matching for type-safe destructuring

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request
No fields configured for Feature.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions