Iterator API Documentation

class Iterator[source]

Bases: Generic[T]

Defines the interface for traversing elements in a collection.

has_next()[source]

Check if there are more elements to traverse.

Return type:

bool

Returns:

True if more elements exist, False otherwise.

next()[source]

Retrieve the next element in the collection.

Return type:

TypeVar(T)

Returns:

The next element.

Raises:

StopIteration – If no more elements exist.

class Aggregate[source]

Bases: Generic[T]

Defines the interface for creating an iterator.

create_iterator()[source]

Create an iterator for the collection.

Return type:

Iterator[TypeVar(T)]

Returns:

An iterator instance.

class ConcreteIterator(collection)[source]

Bases: Iterator[T]

Implements the Iterator interface for traversing a list.

Parameters:

collection (List[T])

__init__(collection)[source]

Initialize the iterator with a collection.

Parameters:

collection (List[TypeVar(T)]) – The collection to iterate over.

has_next()[source]

Check if there are more elements to traverse.

Return type:

bool

Returns:

True if more elements exist, False otherwise.

next()[source]

Retrieve the next element in the collection.

Return type:

TypeVar(T)

Returns:

The next element.

Raises:

StopIteration – If no more elements exist.

class ConcreteAggregate[source]

Bases: Aggregate[T]

Implements the Aggregate interface and provides a method to create an iterator.

__init__()[source]

Initialize an empty collection.

add_item(item)[source]

Add an item to the collection.

Parameters:

item (TypeVar(T)) – The item to add.

Return type:

None

create_iterator()[source]

Create an iterator for the collection.

Return type:

ConcreteIterator[TypeVar(T)]

Returns:

An instance of ConcreteIterator.