Mojo struct
Tuple
The type of a literal tuple expression.
A tuple consists of zero or more values, separated by commas.
Parameters
- *element_types (
Movable
): The elements type.
Fields
- storage (
!kgen.pack<:variadic<trait<@stdlib::@builtin::@value::@Movable>> element_types>
): The underlying storage for the tuple.
Implemented traits
AnyType
,
Movable
,
Sized
Methods
__init__
__init__(inout self: Self, owned *args: *element_types)
Construct the tuple.
Args:
- *args (
*element_types
): Initial values.
__init__(inout self: Self, *, owned storage: VariadicPack[elt_is_mutable, lifetime, Movable, element_types])
Construct the tuple from a low-level internal representation.
Args:
- storage (
VariadicPack[elt_is_mutable, lifetime, Movable, element_types]
): The variadic pack storage to construct from.
__moveinit__
__moveinit__(inout self: Self, owned existing: Self)
Move construct the tuple.
Args:
- existing (
Self
): The value to move from.
__del__
__del__(owned self: Self)
Destructor that destroys all of the elements.
__getitem__
__getitem__[idx: Int](ref [self_is_lifetime] self: Self) -> ref [_] element_types[$0.value]
Get a reference to an element in the tuple.
Parameters:
- idx (
Int
): The element to return.
Returns:
A reference to the specified element.
__contains__
__contains__[T: EqualityComparable](self: Self, value: T) -> Bool
Return whether the tuple contains the specified value.
For example:
var t = Tuple(True, 1, 2.5)
if 1 in t:
print("t contains 1")
var t = Tuple(True, 1, 2.5)
if 1 in t:
print("t contains 1")
Parameters:
- T (
EqualityComparable
): The type of the value.
Args:
- value (
T
): The value to search for.
Returns:
True if the value is in the tuple, False otherwise.
__len__
static __len__() -> Int
Return the number of elements in the tuple.
Returns:
The tuple length.
__len__(self: Self) -> Int
Get the number of elements in the tuple.
Returns:
The tuple length.
get
get[i: Int, T: Movable](self: Self) -> ref [*[0,0]] $1
Get a tuple element and rebind to the specified type.
Parameters:
- i (
Int
): The element index. - T (
Movable
): The element type.
Returns:
The tuple element at the requested index.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?