Skip to content

Peekable

Bases: Pipeable, Checkable

Represents the result of peeking into an Iter.

Inerhit from Checkable to provide truthiness based on whether any elements were peeked.

Attributes:

Name Type Description
peek Seq[T]

A Seq of the peeked elements.

values Iter[T]

An Iter of values, still including the peeked elements.

See Also

Iter.peekable() Iter.cloned()

Example:

>>> import pyochain as pc
>>> it = pc.Iter([1, 2, 3, 4, 5])
>>> peekable = it.peekable(3)
>>> peekable.peek
Seq(1, 2, 3)
>>> peekable.values.collect()
Seq(1, 2, 3, 4, 5)

Source code in src/pyochain/_iter.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@dataclass(slots=True)
class Peekable[T](Pipeable, Checkable):
    """Represents the result of peeking into an `Iter`.

    Inerhit from `Checkable` to provide truthiness based on whether any elements were peeked.

    Attributes:
        peek (Seq[T]): A `Seq` of the peeked elements.
        values (Iter[T]): An `Iter` of values, still including the peeked elements.

    See Also:
        `Iter.peekable()`
        `Iter.cloned()`

    Example:
    ```python
    >>> import pyochain as pc
    >>> it = pc.Iter([1, 2, 3, 4, 5])
    >>> peekable = it.peekable(3)
    >>> peekable.peek
    Seq(1, 2, 3)
    >>> peekable.values.collect()
    Seq(1, 2, 3, 4, 5)

    ```
    """

    peek: Seq[T]
    """A `Seq` of the peeked elements."""
    values: Iter[T]
    """An `Iter` of values, still including the peeked elements."""

    def __bool__(self) -> bool:
        return bool(self.peek)

peek instance-attribute

A Seq of the peeked elements.

values instance-attribute

An Iter of values, still including the peeked elements.