builtin_slice

Module

Implements slice.

These are Mojo built-ins, so you don’t need to import them.

slice

Represents a slice expression.

Objects of this type are generated when slice syntax [a:b:c] is used.

Fields:

  • start (Int): The starting index of the slice.
  • end (Int): The end index of the slice.
  • step (Int): The step increment value of the slice.

Functions:

__init__

__init__(end: Int) -> Self

Construct slice given the end value.

Args:

  • end (Int): The end value.

Returns:

The constructed slice.

__init__(start: Int, end: Int) -> Self

Construct slice given the start and end values.

Args:

  • start (Int): The start value.
  • end (Int): The end value.

Returns:

The constructed slice.

__init__[T0: AnyType, T1: AnyType, T2: AnyType](start: T0, end: T1, step: T2) -> Self

Construct slice given the start, end and step values.

Parameters:

  • T0 (AnyType): Type of the start value.
  • T1 (AnyType): Type of the end value.
  • T2 (AnyType): Type of the step value.

Args:

  • start (T0): The start value.
  • end (T1): The end value.
  • step (T2): The step value.

Returns:

The constructed slice.

__getitem__

__getitem__(self: Self, idx: Int) -> Int

Get the slice index.

Args:

  • idx (Int): The index.

Returns:

The slice index.

__eq__

__eq__(self: Self, other: Self) -> Bool

Compare this slice to the other.

Args:

  • other (Self): The slice to compare to.

Returns:

True if start, end, and step values of this slice match the corresponding values of the other slice and False otherwise.

__ne__

__ne__(self: Self, other: Self) -> Bool

Compare this slice to the other.

Args:

  • other (Self): The slice to compare to.

Returns:

False if start, end, and step values of this slice match the corresponding values of the other slice and True otherwise.

__len__

__len__(self: Self) -> Int

Return the length of the slice.

Returns:

The length of the slice.