Skip to content

Deque

Bases: PyoMutableSequence[T], ArgsWrapper[T]


              flowchart TD
              pyochain.collections._deque.Deque[Deque]
              pyochain.abc._sequences.PyoMutableSequence[PyoMutableSequence]
              pyochain.abc._sequences.PyoSequence[PyoSequence]
              pyochain.abc._sequences.PyoReversible[PyoReversible]
              pyochain.abc._collection.PyoCollection[PyoCollection]
              pyochain.abc._iterable.PyoIterable[PyoIterable]
              pyochain.abc._collection.PyoContainer[PyoContainer]
              pyochain.abc._collection.PyoSized[PyoSized]
              pyochain.abc._mixins.Checkable[Checkable]
              pyochain.abc._mixins.Fluent[Fluent]
              pyochain.abc._mixins.Pipe[Pipe]
              pyochain.abc._mixins.Tap[Tap]
              pyochain.abc.constructors.ArgsWrapper[ArgsWrapper]
              pyochain.abc.constructors.FromArgs[FromArgs]
              pyochain.abc.constructors.FromIter[FromIter]
              pyochain.abc.constructors.Wrapper[Wrapper]

                              pyochain.abc._sequences.PyoMutableSequence --> pyochain.collections._deque.Deque
                                pyochain.abc._sequences.PyoSequence --> pyochain.abc._sequences.PyoMutableSequence
                                pyochain.abc._sequences.PyoReversible --> pyochain.abc._sequences.PyoSequence
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._sequences.PyoReversible
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                



                pyochain.abc._collection.PyoCollection --> pyochain.abc._sequences.PyoSequence
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                


                pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
                

                pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
                




                pyochain.abc.constructors.ArgsWrapper --> pyochain.collections._deque.Deque
                                pyochain.abc.constructors.FromArgs --> pyochain.abc.constructors.ArgsWrapper
                                pyochain.abc.constructors.FromIter --> pyochain.abc.constructors.FromArgs
                

                pyochain.abc.constructors.Wrapper --> pyochain.abc.constructors.ArgsWrapper
                



              click pyochain.collections._deque.Deque href "" "pyochain.collections._deque.Deque"
              click pyochain.abc._sequences.PyoMutableSequence href "" "pyochain.abc._sequences.PyoMutableSequence"
              click pyochain.abc._sequences.PyoSequence href "" "pyochain.abc._sequences.PyoSequence"
              click pyochain.abc._sequences.PyoReversible href "" "pyochain.abc._sequences.PyoReversible"
              click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
              click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
              click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
              click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
              click pyochain.abc._mixins.Checkable href "" "pyochain.abc._mixins.Checkable"
              click pyochain.abc._mixins.Fluent href "" "pyochain.abc._mixins.Fluent"
              click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
              click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
              click pyochain.abc.constructors.ArgsWrapper href "" "pyochain.abc.constructors.ArgsWrapper"
              click pyochain.abc.constructors.FromArgs href "" "pyochain.abc.constructors.FromArgs"
              click pyochain.abc.constructors.FromIter href "" "pyochain.abc.constructors.FromIter"
              click pyochain.abc.constructors.Wrapper href "" "pyochain.abc.constructors.Wrapper"
            

Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”).

Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.

Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.

If max_length is not specified or is None, Deques may grow to an arbitrary length.

Otherwise, the Deque is bounded to the specified maximum length.

Once a bounded length Deque is full, when new items are added, a corresponding number of items are discarded from the opposite end.

Bounded length Deques provide functionality similar to the tail filter in Unix.

They are also useful for tracking transactions and other pools of data where only the most recent activity is of interest.

Note

Adapted from Python Software Foundation documentation for collections.deque.

Copyright (c) 2001-2024 PSF. Used under PSF License.

See https://docs.python.org/3/library/collections.html#collections.deque for more details.

Source code in pyochain/collections/_deque.pyi
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
@final
class Deque[T](PyoMutableSequence[T], ArgsWrapper[T]):
    """Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”).

    Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.

    Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.

    If `max_length` is not specified or is `None`, `Deque`s may grow to an arbitrary length.

    Otherwise, the `Deque` is bounded to the specified maximum length.

    Once a bounded length `Deque` is full, when new items are added, a corresponding number of items are discarded from the opposite end.

    Bounded length `Deque`s provide functionality similar to the tail filter in Unix.

    They are also useful for tracking transactions and other pools of data where only the most recent activity is of interest.

    Note:
        Adapted from Python Software Foundation documentation for `collections.deque`.

        Copyright (c) 2001-2024 PSF. Used under PSF License.

        See https://docs.python.org/3/library/collections.html#collections.deque for more details.
    """

    max_length: Final[int | None]
    """Final[int | None]: the maximum length of the `Deque`.

    If not specified or None, the `Deque` is unbounded."""

    @overload
    def __new__(cls, max_length: int | None = ...) -> Self: ...
    @overload
    def __new__(cls, data: Iterable[T], *, max_length: int | None = ...) -> Self: ...
    @overload
    def __new__(
        cls, data: T, /, *elements: T, max_length: int | None = ...
    ) -> Self: ...
    def __new__(
        cls, data: Iterable[T] | T = (), /, *elements: T, max_length: int | None = None
    ) -> Self:
        """Returns a new `Deque` object initialized left-to-right (using append()) from `data`.

        If no positional arguments are provided, an empty `Deque` is created.

        Args:
            data (Iterable[T] | T): The initial data to populate the `Deque`. Defaults to `()`.
            *elements (T): Additional elements to append to the `Deque` after `data`.
            max_length (int | None): The maximum length of the `Deque`. If not specified or `None`, the `Deque` is unbounded.

        Returns:
            Self: A new `Deque` instance.

        Example:
            ```python
            from pyochain.collections import Deque

            # Create an empty Deque
            assert Deque() == Deque(()) == Deque([])
            assert Deque().is_empty()

            # Create a Deque from an iterable
            assert Deque(1, 2, 3) == Deque(1, 2, 3) == Deque(range(1, 4))
            # Create a Deque from individual elements
            assert Deque(4, 5, 6) == Deque(4, 5, 6)
            # Create a bounded Deque with a maximum length of 3
            assert Deque(range(10), max_length=3) == Deque(7, 8, 9)
            ```
        """

    @override
    def __iter__(self) -> Iterator[T]:
        """Return an iterator over the elements in the deque."""

    def __copy__(self) -> Deque[T]:
        """Return a shallow copy of a deque."""

    @override
    def __len__(self) -> int:
        """Return len(self)."""

    @override
    # pyrefly: ignore [bad-override]
    def __getitem__(self, key: SupportsIndex, /) -> T:  # pyright: ignore[reportIncompatibleMethodOverride]
        """Return self[key]."""

    @override
    # pyrefly: ignore [bad-override]
    def __setitem__(self, key: SupportsIndex, value: T, /) -> None:  # pyright: ignore[reportIncompatibleMethodOverride]
        """Set self[key] to value."""

    @override
    # pyrefly: ignore [bad-override]
    def __delitem__(self, key: SupportsIndex, /) -> None:  # pyright: ignore[reportIncompatibleMethodOverride]
        """Delete self[key]."""

    @override
    def __contains__(self, key: object, /) -> bool:
        """Return bool(key in self)."""

    @override
    def __iadd__(self, value: Iterable[T], /) -> Deque[T]:
        """Implement self+=value.

        Args:
            value (Iterable[T]): The values to add to the right end of the `Deque`.

        Returns:
            Deque[T]: The modified `Deque` instance after in-place addition.
        """

    def __add__(self, value: IntoDeque[T], /) -> Deque[T]:
        """Return self+value."""

    def __mul__(self, value: int, /) -> Deque[T]:
        """Return self*value."""

    def __rmul__(self, value: int, /) -> Deque[T]: ...
    def __imul__(self, value: int, /) -> Deque[T]:
        """Implement self*=value.

        Args:
            value (int): The number of times to repeat the `Deque`.

        Returns:
            Deque[T]: The modified `Deque` instance after in-place multiplication.
        """

    def __lt__(self, value: IntoDeque[T], /) -> bool:
        """Return self<value."""

    def __le__(self, value: IntoDeque[T], /) -> bool:
        """Return self<=value."""

    def __gt__(self, value: IntoDeque[T], /) -> bool:
        """Return self>value."""

    def __ge__(self, value: IntoDeque[T], /) -> bool:
        """Return self>=value."""

    @override
    def __eq__(self, value: object, /) -> bool:
        """Return self==value."""
    @override
    @staticmethod
    def of[T1](*elements: T1, max_length: int | None = None) -> Deque[T1]: ...
    @override
    @staticmethod
    def from_iter[T1](
        iterable: Iterable[T1], /, max_length: int | None = None
    ) -> Deque[T1]: ...
    @override
    @staticmethod
    def wrap[T1](data: deque[T1]) -> Deque[T1]: ...  # pyright: ignore[reportIncompatibleMethodOverride]
    @override
    def append(self, x: T, /) -> None: ...
    def append_left(self, x: T, /) -> None:
        """Add an element to the left side of the deque.

        Args:
            x (T): The element to add to the left side of the `Deque`.

        Examples:
            ```python
            from pyochain.collections import Deque

            d = Deque(1, 2, 3)
            d.append_left(0)

            assert d == Deque(0, 1, 2, 3)
            ```
        """

    @override
    def extend(self, iterable: Iterable[T]) -> None: ...
    @override
    def clear(self) -> None: ...
    def copy(self) -> Deque[T]:
        """Return a shallow copy of a deque.

        Returns:
            Deque[T]: A new `Deque` instance that is a shallow copy of the original.

        Example:
            ```python
            from pyochain.collections import Deque

            d = Deque(1, 2, 3)
            d_copy = d.copy()

            assert d_copy == Deque(1, 2, 3)
            d.append(4)
            assert d == Deque(1, 2, 3, 4)
            assert d_copy == Deque(1, 2, 3)
            ```
        """

    def extend_left(self, iterable: Iterable[T], /) -> None:
        """Extend the left side of the deque with elements from the iterable.

        Args:
            iterable (Iterable[T]): The elements to add to the left side of the `Deque`.

        Examples:
            ```python
            from pyochain.collections import Deque

            d = Deque(1, 2, 3)
            d.extend_left([0, -1])

            assert d == Deque(-1, 0, 1, 2, 3)
            ```
        """

    def pop_left(self) -> T:
        """Remove and return the leftmost element.

        Returns:
            T: The leftmost element of the deque.

        Examples:
            ```python
            from pyochain.collections import Deque

            d = Deque(1, 2, 3)

            assert d.pop_left() == 1
            assert d == Deque(2, 3)
            ```
        """

    def rotate(self, n: int = 1, /) -> Self:
        """Rotate the deque n steps.

        Args:
            n (int): The number of steps to rotate the deque. If n is positive, rotates right. if negative, rotates left.

        Returns:
            Self: The modified `Deque` instance after rotation.

        Examples:
            ```python
            from pyochain.collections import Deque

            d = Deque(1, 2, 3, 4, 5)

            assert d.rotate(2) == Deque(4, 5, 1, 2, 3)
            assert d.rotate(-3) == Deque(2, 3, 4, 5, 1)
            ```
        """

    @override
    def insert(self, index: int, value: T) -> None:
        """Insert value before index."""

    @override
    def count(self, x: T, /) -> int: ...
    @override
    def index(self, x: T, start: int = 0, stop: int = ..., /) -> int: ...
    @override
    # pyrefly: ignore [bad-override]
    def pop(self) -> T: ...  # pyright: ignore[reportIncompatibleMethodOverride]
    @override
    def remove(self, value: T, /) -> None: ...

max_length instance-attribute

Final[int | None]: the maximum length of the Deque.

If not specified or None, the Deque is unbounded.

__new__(data=(), /, *elements, max_length=None)

__new__(max_length: int | None = ...) -> Self
__new__(
    data: Iterable[T], *, max_length: int | None = ...
) -> Self
__new__(
    data: T, /, *elements: T, max_length: int | None = ...
) -> Self

Returns a new Deque object initialized left-to-right (using append()) from data.

If no positional arguments are provided, an empty Deque is created.

Parameters:

Name Type Description Default
data Iterable[T] | T

The initial data to populate the Deque. Defaults to ().

()
*elements T

Additional elements to append to the Deque after data.

()
max_length int | None

The maximum length of the Deque. If not specified or None, the Deque is unbounded.

None

Returns:

Name Type Description
Self Self

A new Deque instance.

Example
from pyochain.collections import Deque

# Create an empty Deque
assert Deque() == Deque(()) == Deque([])
assert Deque().is_empty()

# Create a Deque from an iterable
assert Deque(1, 2, 3) == Deque(1, 2, 3) == Deque(range(1, 4))
# Create a Deque from individual elements
assert Deque(4, 5, 6) == Deque(4, 5, 6)
# Create a bounded Deque with a maximum length of 3
assert Deque(range(10), max_length=3) == Deque(7, 8, 9)
Source code in pyochain/collections/_deque.pyi
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def __new__(
    cls, data: Iterable[T] | T = (), /, *elements: T, max_length: int | None = None
) -> Self:
    """Returns a new `Deque` object initialized left-to-right (using append()) from `data`.

    If no positional arguments are provided, an empty `Deque` is created.

    Args:
        data (Iterable[T] | T): The initial data to populate the `Deque`. Defaults to `()`.
        *elements (T): Additional elements to append to the `Deque` after `data`.
        max_length (int | None): The maximum length of the `Deque`. If not specified or `None`, the `Deque` is unbounded.

    Returns:
        Self: A new `Deque` instance.

    Example:
        ```python
        from pyochain.collections import Deque

        # Create an empty Deque
        assert Deque() == Deque(()) == Deque([])
        assert Deque().is_empty()

        # Create a Deque from an iterable
        assert Deque(1, 2, 3) == Deque(1, 2, 3) == Deque(range(1, 4))
        # Create a Deque from individual elements
        assert Deque(4, 5, 6) == Deque(4, 5, 6)
        # Create a bounded Deque with a maximum length of 3
        assert Deque(range(10), max_length=3) == Deque(7, 8, 9)
        ```
    """

__iter__()

Return an iterator over the elements in the deque.

Source code in pyochain/collections/_deque.pyi
81
82
83
@override
def __iter__(self) -> Iterator[T]:
    """Return an iterator over the elements in the deque."""

__copy__()

Return a shallow copy of a deque.

Source code in pyochain/collections/_deque.pyi
85
86
def __copy__(self) -> Deque[T]:
    """Return a shallow copy of a deque."""

__len__()

Return len(self).

Source code in pyochain/collections/_deque.pyi
88
89
90
@override
def __len__(self) -> int:
    """Return len(self)."""

__getitem__(key)

Return self[key].

Source code in pyochain/collections/_deque.pyi
92
93
94
95
@override
# pyrefly: ignore [bad-override]
def __getitem__(self, key: SupportsIndex, /) -> T:  # pyright: ignore[reportIncompatibleMethodOverride]
    """Return self[key]."""

__setitem__(key, value)

Set self[key] to value.

Source code in pyochain/collections/_deque.pyi
 97
 98
 99
100
@override
# pyrefly: ignore [bad-override]
def __setitem__(self, key: SupportsIndex, value: T, /) -> None:  # pyright: ignore[reportIncompatibleMethodOverride]
    """Set self[key] to value."""

__delitem__(key)

Delete self[key].

Source code in pyochain/collections/_deque.pyi
102
103
104
105
@override
# pyrefly: ignore [bad-override]
def __delitem__(self, key: SupportsIndex, /) -> None:  # pyright: ignore[reportIncompatibleMethodOverride]
    """Delete self[key]."""

__contains__(key)

Return bool(key in self).

Source code in pyochain/collections/_deque.pyi
107
108
109
@override
def __contains__(self, key: object, /) -> bool:
    """Return bool(key in self)."""

__iadd__(value)

Implement self+=value.

Parameters:

Name Type Description Default
value Iterable[T]

The values to add to the right end of the Deque.

required

Returns:

Type Description
Deque[T]

Deque[T]: The modified Deque instance after in-place addition.

Source code in pyochain/collections/_deque.pyi
111
112
113
114
115
116
117
118
119
120
@override
def __iadd__(self, value: Iterable[T], /) -> Deque[T]:
    """Implement self+=value.

    Args:
        value (Iterable[T]): The values to add to the right end of the `Deque`.

    Returns:
        Deque[T]: The modified `Deque` instance after in-place addition.
    """

__add__(value)

Return self+value.

Source code in pyochain/collections/_deque.pyi
122
123
def __add__(self, value: IntoDeque[T], /) -> Deque[T]:
    """Return self+value."""

__mul__(value)

Return self*value.

Source code in pyochain/collections/_deque.pyi
125
126
def __mul__(self, value: int, /) -> Deque[T]:
    """Return self*value."""

__imul__(value)

Implement self*=value.

Parameters:

Name Type Description Default
value int

The number of times to repeat the Deque.

required

Returns:

Type Description
Deque[T]

Deque[T]: The modified Deque instance after in-place multiplication.

Source code in pyochain/collections/_deque.pyi
129
130
131
132
133
134
135
136
137
def __imul__(self, value: int, /) -> Deque[T]:
    """Implement self*=value.

    Args:
        value (int): The number of times to repeat the `Deque`.

    Returns:
        Deque[T]: The modified `Deque` instance after in-place multiplication.
    """

__lt__(value)

Return self<value.

Source code in pyochain/collections/_deque.pyi
139
140
def __lt__(self, value: IntoDeque[T], /) -> bool:
    """Return self<value."""

__le__(value)

Return self<=value.

Source code in pyochain/collections/_deque.pyi
142
143
def __le__(self, value: IntoDeque[T], /) -> bool:
    """Return self<=value."""

__gt__(value)

Return self>value.

Source code in pyochain/collections/_deque.pyi
145
146
def __gt__(self, value: IntoDeque[T], /) -> bool:
    """Return self>value."""

__ge__(value)

Return self>=value.

Source code in pyochain/collections/_deque.pyi
148
149
def __ge__(self, value: IntoDeque[T], /) -> bool:
    """Return self>=value."""

__eq__(value)

Return self==value.

Source code in pyochain/collections/_deque.pyi
151
152
153
@override
def __eq__(self, value: object, /) -> bool:
    """Return self==value."""

append_left(x)

Add an element to the left side of the deque.

Parameters:

Name Type Description Default
x T

The element to add to the left side of the Deque.

required

Examples:

from pyochain.collections import Deque

d = Deque(1, 2, 3)
d.append_left(0)

assert d == Deque(0, 1, 2, 3)
Source code in pyochain/collections/_deque.pyi
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def append_left(self, x: T, /) -> None:
    """Add an element to the left side of the deque.

    Args:
        x (T): The element to add to the left side of the `Deque`.

    Examples:
        ```python
        from pyochain.collections import Deque

        d = Deque(1, 2, 3)
        d.append_left(0)

        assert d == Deque(0, 1, 2, 3)
        ```
    """

copy()

Return a shallow copy of a deque.

Returns:

Type Description
Deque[T]

Deque[T]: A new Deque instance that is a shallow copy of the original.

Example
from pyochain.collections import Deque

d = Deque(1, 2, 3)
d_copy = d.copy()

assert d_copy == Deque(1, 2, 3)
d.append(4)
assert d == Deque(1, 2, 3, 4)
assert d_copy == Deque(1, 2, 3)
Source code in pyochain/collections/_deque.pyi
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def copy(self) -> Deque[T]:
    """Return a shallow copy of a deque.

    Returns:
        Deque[T]: A new `Deque` instance that is a shallow copy of the original.

    Example:
        ```python
        from pyochain.collections import Deque

        d = Deque(1, 2, 3)
        d_copy = d.copy()

        assert d_copy == Deque(1, 2, 3)
        d.append(4)
        assert d == Deque(1, 2, 3, 4)
        assert d_copy == Deque(1, 2, 3)
        ```
    """

extend_left(iterable)

Extend the left side of the deque with elements from the iterable.

Parameters:

Name Type Description Default
iterable Iterable[T]

The elements to add to the left side of the Deque.

required

Examples:

from pyochain.collections import Deque

d = Deque(1, 2, 3)
d.extend_left([0, -1])

assert d == Deque(-1, 0, 1, 2, 3)
Source code in pyochain/collections/_deque.pyi
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def extend_left(self, iterable: Iterable[T], /) -> None:
    """Extend the left side of the deque with elements from the iterable.

    Args:
        iterable (Iterable[T]): The elements to add to the left side of the `Deque`.

    Examples:
        ```python
        from pyochain.collections import Deque

        d = Deque(1, 2, 3)
        d.extend_left([0, -1])

        assert d == Deque(-1, 0, 1, 2, 3)
        ```
    """

pop_left()

Remove and return the leftmost element.

Returns:

Name Type Description
T T

The leftmost element of the deque.

Examples:

from pyochain.collections import Deque

d = Deque(1, 2, 3)

assert d.pop_left() == 1
assert d == Deque(2, 3)
Source code in pyochain/collections/_deque.pyi
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
def pop_left(self) -> T:
    """Remove and return the leftmost element.

    Returns:
        T: The leftmost element of the deque.

    Examples:
        ```python
        from pyochain.collections import Deque

        d = Deque(1, 2, 3)

        assert d.pop_left() == 1
        assert d == Deque(2, 3)
        ```
    """

rotate(n=1)

Rotate the deque n steps.

Parameters:

Name Type Description Default
n int

The number of steps to rotate the deque. If n is positive, rotates right. if negative, rotates left.

1

Returns:

Name Type Description
Self Self

The modified Deque instance after rotation.

Examples:

from pyochain.collections import Deque

d = Deque(1, 2, 3, 4, 5)

assert d.rotate(2) == Deque(4, 5, 1, 2, 3)
assert d.rotate(-3) == Deque(2, 3, 4, 5, 1)
Source code in pyochain/collections/_deque.pyi
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def rotate(self, n: int = 1, /) -> Self:
    """Rotate the deque n steps.

    Args:
        n (int): The number of steps to rotate the deque. If n is positive, rotates right. if negative, rotates left.

    Returns:
        Self: The modified `Deque` instance after rotation.

    Examples:
        ```python
        from pyochain.collections import Deque

        d = Deque(1, 2, 3, 4, 5)

        assert d.rotate(2) == Deque(4, 5, 1, 2, 3)
        assert d.rotate(-3) == Deque(2, 3, 4, 5, 1)
        ```
    """

insert(index, value)

Insert value before index.

Source code in pyochain/collections/_deque.pyi
262
263
264
@override
def insert(self, index: int, value: T) -> None:
    """Insert value before index."""