Skip to content

generators.utils.base

Data - Generators - Base¤

ConstantIterator ¤

An iterator that emits constant values.

pe = ConstantIterator(constant=1)
next(pe)

:param constant: the constant value to be emmited.

Source code in eerily/generators/utils/base.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class ConstantIterator:
    """An iterator that emits constant values.

    ```python
    pe = ConstantIterator(constant=1)
    next(pe)
    ```

    :param constant: the constant value to be emmited.
    """

    def __init__(self, constant: Any):
        self.constant = constant

    def __iter__(self):
        return self

    def __next__(self) -> Any:
        return self.constant