Skip to main content

Mojo trait

Indexer

This trait denotes a type that can be used to index a container that handles integral index values.

This solves the issue of being able to index data structures such as List with the various integral types without being too broad and allowing types that are coercible to Int (e.g. floating point values that have __int__ method). In contrast to Intable, types conforming to Indexer must be convertible to Int in a lossless way.

Note that types conforming to Indexer are implicitly convertible to Int.

Implemented traits

AnyType

Methods

__index__

__index__(self: T) -> Int

Return the index value.

Returns:

The index value of the object.