IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

anytype

Existential-type helpers built on AnyType.

This module defines Some and SomeTypeList, aliases that let a function signature express "any type conforming to trait X" without introducing an explicit type parameter.

comptime values​

Some​

comptime Some[Trait: AnyTrait[AnyType]] = comptime[T: Trait] T

An alias allowing users to tersely express that a function argument is an instance of a type that implements a trait or trait composition.

For example, instead of writing

def foo[T: Intable, //](x: T) -> Int:
return x.__int__()

one can write:

def foo(x: Some[Intable]) -> Int:
return x.__int__()

Parameters​

  • ​Trait (AnyTrait[AnyType]): The trait or trait composition that the argument type must implement.

SomeTypeList​

comptime SomeTypeList[Trait: AnyTrait[AnyType]] = comptime[values: KGENParamList[Trait]] TypeList[values]()

An alias allowing users to tersely express that a function argument is a list of types that implement a trait or trait composition. This is particularly useful for variadic packs.

For example, instead of writing

def foo[*arg_types: Copyable](*args: *arg_types) -> Int: ...

one can write:

def foo(*args: *SomeTypeList[Copyable]) -> Int: ...

Parameters​

  • ​Trait (AnyTrait[AnyType]): The trait or trait composition that the argument types must implement.