Skip to main content

Mojo struct

Tuple

struct Tuple[*element_types: Copyable & Movable]

The type of a literal tuple expression.

A tuple consists of zero or more values, separated by commas.

Parameters

Fields

  • storage (!kgen.pack<:variadic<trait<@stdlib::@builtin::@value::@Copyable, @stdlib::@builtin::@value::@Movable>> element_types>): The underlying storage for the tuple.

Implemented traits

AnyType, Copyable, ImplicitlyCopyable, Movable, Sized, UnknownDestructibility

Aliases

__copyinit__is_trivial

comptime __copyinit__is_trivial = False

__del__is_trivial

comptime __del__is_trivial = False

__moveinit__is_trivial

comptime __moveinit__is_trivial = False

Methods

__init__

__init__(out self: Tuple[])

Construct an empty tuple.

Returns:

Tuple

__init__(out self, var *args: *element_types)

Construct the tuple.

Args:

  • *args (*element_types): Initial values.

__init__(out self, *, var storage: VariadicPack[is_owned, origin, Copyable & Movable, element_types])

Construct the tuple from a low-level internal representation.

Args:

  • storage (VariadicPack[is_owned, origin, Copyable & Movable, element_types]): The variadic pack storage to construct from.

__init__[*elt_types: Copyable & Movable & Defaultable](out self: Tuple[elt_types])

Construct a tuple with default-initialized elements.

Parameters:

Returns:

Tuple

__copyinit__

__copyinit__(out self, existing: Self)

Copy construct the tuple.

Args:

  • existing (Self): The value to copy from.

__moveinit__

__moveinit__(out self, deinit existing: Self)

Move construct the tuple.

Args:

  • existing (Self): The value to move from.

__del__

__del__(deinit self)

Destructor that destroys all of the elements.

__getitem__

__getitem__[idx: Int](ref self) -> ref [self] element_types[idx._mlir_value]

Get a reference to an element in the tuple.

Parameters:

  • idx (Int): The element to return.

Returns:

ref: A reference to the specified element.

__lt__

__lt__[self_elt_types: Variadic[Copyable & Movable & Comparable], other_elt_types: Variadic[Copyable & Movable & Comparable], //](self: Tuple[self_elt_types], other: Tuple[other_elt_types]) -> Bool

Compare this tuple to another tuple using less than comparison.

Parameters:

  • self_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the Tuple.
  • other_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to compare against.

Returns:

Bool: True if this tuple is less than the other tuple, False otherwise.

__le__

__le__[self_elt_types: Variadic[Copyable & Movable & Comparable], other_elt_types: Variadic[Copyable & Movable & Comparable], //](self: Tuple[self_elt_types], other: Tuple[other_elt_types]) -> Bool

Compare this tuple to another tuple using less than or equal to comparison.

Parameters:

  • self_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the Tuple.
  • other_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to compare against.

Returns:

Bool: True if this tuple is less than or equal to the other tuple, False otherwise.

__eq__

__eq__[self_elt_types: Variadic[Copyable & Movable & Equatable], other_elt_types: Variadic[Copyable & Movable & Equatable]](self: Tuple[self_elt_types], other: Tuple[other_elt_types]) -> Bool

Compare this tuple to another tuple using equality comparison.

Parameters:

  • self_elt_types (Variadic & Movable & Equatable]): The types of the elements contained in the Tuple.
  • other_elt_types (Variadic & Movable & Equatable]): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to compare against.

Returns:

Bool: True if this tuple is equal to the other tuple, False otherwise.

__ne__

__ne__[self_elt_types: Variadic[Copyable & Movable & Equatable], other_elt_types: Variadic[Copyable & Movable & Equatable]](self: Tuple[self_elt_types], other: Tuple[other_elt_types]) -> Bool

Compare this tuple to another tuple using inequality comparison.

Parameters:

  • self_elt_types (Variadic & Movable & Equatable]): The types of the elements contained in the Tuple.
  • other_elt_types (Variadic & Movable & Equatable]): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to compare against.

Returns:

Bool: True if this tuple is not equal to the other tuple, False otherwise.

__gt__

__gt__[self_elt_types: Variadic[Copyable & Movable & Comparable], other_elt_types: Variadic[Copyable & Movable & Comparable], //](self: Tuple[self_elt_types], other: Tuple[other_elt_types]) -> Bool

Compare this tuple to another tuple using greater than comparison.

Parameters:

  • self_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the Tuple.
  • other_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to compare against.

Returns:

Bool: True if this tuple is greater than the other tuple, False otherwise.

__ge__

__ge__[self_elt_types: Variadic[Copyable & Movable & Comparable], other_elt_types: Variadic[Copyable & Movable & Comparable], //](self: Tuple[self_elt_types], other: Tuple[other_elt_types]) -> Bool

Compare this tuple to another tuple using greater than or equal to comparison.

Parameters:

  • self_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the Tuple.
  • other_elt_types (Variadic & Movable & Comparable]): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to compare against.

Returns:

Bool: True if this tuple is greater than or equal to the other tuple, False otherwise.

__contains__

__contains__[T: Equatable](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")

Parameters:

Args:

  • value (T): The value to search for.

Returns:

Bool: True if the value is in the tuple, False otherwise.

__len__

static __len__() -> Int

Return the number of elements in the tuple.

Returns:

Int: The tuple length.

__len__(self) -> Int

Get the number of elements in the tuple.

Returns:

Int: The tuple length.

reverse

reverse(deinit self, out result: Tuple[#kgen.variadic.reduce<#kgen.variadic<> : !kgen.variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>, #kgen.param.decl.ref<"element_types"> : !kgen.variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>, #kgen.gen<#kgen.variadic.concat<#kgen.variadic<*(0,0), [variadic_get(:variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>> *(0,1), add(mul(*(0,2), -1), #kgen.variadic.size<#kgen.param.index.ref<0, 1> : !kgen.variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>>, -1))]> : !kgen.variadic<variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>>>> : !kgen.generator<!lit.generator<<"PrevV": variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>, "VA": variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>, "idx": index>variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>>>>])

Return a new tuple with the elements in reverse order.

Returns:

Tuple: A new tuple with the elements in reverse order.

concat

concat[*other_element_types: Copyable & Movable](deinit self, deinit other: Tuple[other_element_types], out result: Tuple[#kgen.variadic.concat<#kgen.variadic<element_types, other_element_types> : !kgen.variadic<variadic<trait<_stdlib::_builtin::_value::_Copyable, _stdlib::_builtin::_value::_Movable>>>>])

Return a new tuple that concatenates this tuple with another.

Parameters:

  • *other_element_types (Copyable & Movable): The types of the elements contained in the other Tuple.

Args:

  • other (Tuple): The other tuple to concatenate.

Returns:

Tuple: A new tuple with the concatenated elements.

Was this page helpful?