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).

Iterable

Describes a type that can produce an iterator by borrowing.

Conforming types implement __iter__(ref self), which borrows the collection (immutably or mutably, depending on the call-site origin) and returns an iterator whose elements may reference the source data. The collection remains usable after iteration.

Implemented traits

AnyType

comptime members

IteratorType

comptime IteratorType[iterable_mut: Bool, //, iterable_origin: Origin[mut=iterable_mut]]

The iterator type returned when borrowing this collection.

Parameterized on the mutability and origin so the iterator can yield references tied to the source collection's origin.

Parameters

Required methods

__iter__

def __iter__(ref self: _Self) -> _Self.IteratorType[self_is_mut, origin_of(self), origin_of(self)]

Borrows the collection and returns an iterator over its elements.

Returns:

_Self.IteratorType[self_is_mut, origin_of(self), origin_of(self)]: An iterator over the elements.