Skip to main content

Mojo trait

IterableOwned

Describes a type that can produce an iterator by giving up ownership.

Conforming types implement __iter__(var self), which takes the collection by value and returns an iterator that owns the underlying data.

Use IterableOwned when the caller no longer needs the collection after iteration, or when yielding owned elements is more natural (e.g. draining a temporary result).

Implemented traits

AnyType

comptime members

IteratorOwnedType

comptime IteratorOwnedType

The iterator type returned when the collection is consumed.

Required methods

__iter__

__iter__(var self: _Self) -> _Self.IteratorOwnedType

Consumes the collection and returns an iterator over its elements.

Returns:

_Self.IteratorOwnedType: An iterator that owns the collection's elements.

Was this page helpful?