LazyIterator

class LazyIterator[T]

Description

A base type for all internally-iterated objects.

Such objects are only iterable through .for_each method, rather than Python standard .__iter__:

def visitor(value: T) -> None | bool | VisitAction:
    ...

iterator.for_each(visitor)

This allows generating internally iterated sequences on-the-fly while keeping performance overhead low, e.g. combining multiple sequences while traversing a graph. In most cases, this is not as easy to implement with external iteration otherwise.

Inheritance:

Children
Members defined in LazyIterator (7 members)

__bool__

Returns True if this range is not empty.

at

Get value at index. This is computed lazily. Returns None for out of bounds index.

collect

Collect all items into a list.

count

Count the number of items in this range. This is computed lazily.

empty

Check if this range is empty.

for_each

Lazily visit each item in this range. Visitation is stopped on returning False or VisitAction.Stop;

get

Get value at index, This is computed lazily. Throws IndexError on out of bounds.

Methods

__bool__() → bool

Returns True if this range is not empty.

at(arg0: int, /) → syside.T | None

Get value at index. This is computed lazily. Returns None for out of bounds index.

Notes:

  • Has complexity O(n) so should be used sparingly.

  • Only positive indices are allowed since size is unknown.

collect() → list[syside.T]

Collect all items into a list.

count() → int

Count the number of items in this range. This is computed lazily.

empty() → bool

Check if this range is empty.

for_each(arg0: Callable[[syside.T], None | bool | syside.VisitAction], /) → None

Lazily visit each item in this range. Visitation is stopped on returning False or VisitAction.Stop;

get(arg0: int, /) → syside.T

Get value at index, This is computed lazily. Throws IndexError on out of bounds.

Notes:

  • Has complexity O(n) so should be used sparingly.

  • Only positive indices are allowed since size is unknown.

Used by