Skip to main content

Mojo struct

Variadic

struct Variadic

A namespace for variadic utilities.

Implemented traits

AnyType, ImplicitlyDestructible

comptime members

concat_types

comptime concat_types[T: AnyTrait[AnyType], //, *Ts: KGENParamList[T]] = #kgen.param_list.concat(values)

Represents the concatenation of multiple variadic sequences of types.

Parameters

  • T (AnyTrait): The trait that types in the variadic sequences must conform to.
  • *Ts (KGENParamList): The variadic sequences to concatenate.

concat_values

comptime concat_values[T: AnyType, //, *Ts: KGENParamList[T]] = #kgen.param_list.concat(values)

Represents the concatenation of multiple variadic sequences of values.

Parameters

  • T (AnyType): The types of the values in the variadic sequences.
  • *Ts (KGENParamList): The variadic sequences to concatenate.

empty_of_trait

comptime empty_of_trait[T: AnyTrait[AnyType]]

Empty comptime variadic of type values.

Parameters

  • T (AnyTrait): The trait that types in the variadic sequence must conform to.

slice_types

comptime slice_types[T: AnyTrait[AnyType], //, element_types: KGENParamList[T], start: Int where (start >= 0) = 0, end: Int where (end <= TypeList[element_types].size) if (start <= end) else (start <= end) = TypeList[element_types].size] = TypeList[#kgen.param_list.reduce(element_types, base=, reducer=[PrevV: KGENParamList[T], VA: KGENParamList[T], idx: __mlir_type.index] #kgen.param_list.concat(PrevV, VA[idx]) if (idx < end) if (idx >= start) else (idx >= start) else PrevV)]

Extract a contiguous subsequence from a variadic sequence.

Returns a new variadic containing elements from index start (inclusive) to index end (exclusive). Similar to Python's slice notation [start:end].

Constraints: - 0 <= start <= end <= TypeList[element_types].size

Examples:

from std.builtin.variadics import Variadic

# Given a variadic of types [Int, String, Float64, Bool]
comptime MyTypes = Tuple[Int, String, Float64, Bool].element_types
# Extract middle elements: [String, Float64]
comptime Sliced = Variadic.slice_types[start=1, end=3, element_types=MyTypes]
# Extract first two: [Int, String]
comptime First2 = Variadic.slice_types[start=0, end=2, element_types=MyTypes]
# Extract last element: [Bool]
comptime Last = Variadic.slice_types[start=3, end=4, element_types=MyTypes]

Parameters

  • T (AnyTrait): The trait that the types conform to.
  • element_types (KGENParamList): The variadic sequence to slice.
  • start (Int): The starting index (inclusive).
  • end (Int): The ending index (exclusive).

types

comptime types[T: AnyTrait[AnyType], //, *Ts: T] = values

Turn discrete type values (bound by T) into a single variadic.

Parameters

  • T (AnyTrait): The trait that the types must conform to.
  • *Ts (T): The types to collect into a variadic sequence.

TypesOfTrait

comptime TypesOfTrait[T: AnyTrait[AnyType]] = KGENParamList[T]

Represents a raw variadic sequence of types that satisfy the specified trait.

Parameters

  • T (AnyTrait): The trait that types in the variadic sequence must conform to.

values

comptime values[T: AnyType, //, *values_: T]

Turn discrete values (bound by T) into a single variadic.

Parameters

  • T (AnyType): The type of the values.
  • *values_ (T): The values to collect into a variadic sequence.

ValuesOfType

comptime ValuesOfType[type: AnyType] = KGENParamList[type]

Represents a raw variadic sequence of values of the specified type.

Parameters

  • type (AnyType): The type of values in the variadic sequence.

zip_types

comptime zip_types[Trait: AnyTrait[AnyType], //, *types: KGENParamList[Trait]] = ParameterList[#kgen.param_list.zip(values)]

Zips a group of variadics of types together.

Parameters

  • Trait (AnyTrait): The trait that the types conform to.
  • *types (KGENParamList): The type to check for.

zip_values

comptime zip_values[type: AnyType, //, *values: KGENParamList[type]] = ParameterList[#kgen.param_list.zip(values)]

Zips a group of variadics of values together.

Parameters

  • type (AnyType): The type that the values conform to.
  • *values (KGENParamList): The values to zip.

Was this page helpful?