Skip to content

sonolus.script.iterator

SonolusIterator

Base class for Sonolus iterators.

This class is used to define custom iterators that can be used in Sonolus.py.

Inheritors must implement the next method, which should return a Maybe[T].

An iterator should be treated as single use: do not advance one that is already being consumed, or consume one again after it is exhausted. Doing so may lead to unexpected behavior.

Usage
class MyIterator(Record, SonolusIterator):
    def next(self) -> Maybe[T]:
        ...

__iter__() -> SonolusIterator[T]

Return the iterator itself.

__next__() -> T

Return the next item, for use outside of compiled code only.

This is not intended to be overridden, and just serves to allow iterators to work in regular Python code.

next() -> Maybe[T]

Return the next item from the iterator as a Maybe.

maybe_next(iterator: Iterator[T]) -> Maybe[T]

Get the next item from an iterator as a Maybe.

The iterator must be a SonolusIterator instance.