Tekvel Magic
Loading...
Searching...
No Matches
InfiniteIterator Class Reference

Infinite iterator for cycling through a list of values. More...

Public Member Functions

def __init__ (self, values)
 Initializes the InfiniteIterator with a list of values. More...
 
def __iter__ (self)
 Initializes the InfiniteIterator with a list of values. More...
 
def __next__ (self)
 Returns the iterator object itself. More...
 

Public Attributes

 values
 
 current_position
 
 current_value
 

Detailed Description

Infinite iterator for cycling through a list of values.

This class provides an infinite iterator that continuously cycles through a list of values. Each iteration returns a tuple containing the current value and its index within the list. The index is updated as the iterator loops through the values repeatedly. Useful for scenarios where cyclic iteration over a dataset is required, such as generating test patterns or simulating states.

Example usage:

values = ["A", "B", "C"]
iterator = InfiniteIterator(values)
for i in range(10): # Iterate 10 times
value, index = next(iterator)
print(f"Cycle {i}: Value={value}, Index={index}")

Output:

Cycle 0: Value=A, Index=0
Cycle 1: Value=B, Index=1
Cycle 2: Value=C, Index=2
Cycle 3: Value=A, Index=0
...

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  values 
)

Initializes the InfiniteIterator with a list of values.

Sets up the iterator with the provided list of values and prepares it for infinite cycling.

Parameters
valuesList of values to iterate over.

Member Function Documentation

◆ __iter__()

def __iter__ (   self)

Initializes the InfiniteIterator with a list of values.

Sets up the iterator with the provided list of values and prepares it for infinite cycling.

Parameters
valuesList of values to iterate over.

◆ __next__()

def __next__ (   self)

Returns the iterator object itself.

Enables the object to be used in iteration contexts such as loops.

Returns
The iterator object itself.

Member Data Documentation

◆ current_position

current_position

◆ current_value

current_value

◆ values

values