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 has_next, get, and advance methods. The __next__ and __iter__ methods are implemented by default.

Usage
class MyIterator(Record, SonolusIterator):
    def has_next(self) -> bool:
        ...

    def get(self) -> Any:
        ...

    def advance(self):
        ...

advance() abstractmethod

Advance the iterator to the next element.

Must not be called if has_next returns False.

get() abstractmethod

Return the next element of the iterator.

May be called multiple times before calling advance.

Must not be called if has_next returns False.

has_next() abstractmethod

Return whether the iterator has more elements.