pythonic-fp-queues 5.1.0__py3-none-any.whl → 5.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # Copyright 2023-2024 Geoffrey R. Scheller
1
+ # Copyright 2023-2026 Geoffrey R. Scheller
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,20 +14,18 @@
14
14
 
15
15
  """
16
16
  Queues
17
- ======
17
+ ------
18
18
 
19
- +-------------------------+-----------+--------------------------+
20
- | module | class | name |
21
- +=========================+===========+==========================+
22
- | pythonic_fp.queues.fifo | FIFOQueue | First-In-First-Out Queue |
23
- +-------------------------+-----------+--------------------------+
24
- | pythonic_fp.queues.lifo | LIFOQueue | Last-In-First-Out Queue |
25
- +-------------------------+-----------+--------------------------+
26
- | pythonic_fp.queues.de | DEQueue | Double-Ended Queue |
27
- +-------------------------+-----------+--------------------------+
19
+ .. admonition:: Stateful Queues
20
+
21
+ By limiting how their data can be accessed, each queue type
22
+ supports different algorithmic use cases.
23
+
24
+ Sometimes the power of a data structure comes not what it empowers
25
+ you to do, but what it prevents you from doing to yourself.
28
26
 
29
27
  """
30
28
 
31
29
  __author__ = 'Geoffrey R. Scheller'
32
- __copyright__ = 'Copyright (c) 2023-2025 Geoffrey R. Scheller'
30
+ __copyright__ = 'Copyright (c) 2023-2026 Geoffrey R. Scheller'
33
31
  __license__ = 'Apache License 2.0'
File without changes
pythonic_fp/queues/de.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2023-2025 Geoffrey R. Scheller
1
+ # Copyright 2023-2026 Geoffrey R. Scheller
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -21,14 +21,18 @@ __all__ = ['DEQueue', 'de_queue']
21
21
 
22
22
 
23
23
  class DEQueue[D]:
24
- """Stateful Double-Ended (DE) Queue data structure.
24
+ """
25
+ .. admonition:: DEQueue
26
+
27
+ Stateful Double-Ended (DE) Queue data structure.
25
28
 
26
- - O(1) pops each end
27
- - O(1) amortized pushes each end
28
- - O(1) length determination
29
- - in a Boolean context, truthy if not empty, falsy if empty
30
- - will automatically increase storage capacity when needed
31
- - neither indexable nor sliceable by design
29
+ - has a left and a right side
30
+ - O(1) pops each end
31
+ - O(1) amortized pushes each end
32
+ - O(1) length determination
33
+ - in a Boolean context, truthy if not empty, falsy if empty
34
+ - will automatically increase storage capacity when needed
35
+ - neither indexable nor sliceable by design
32
36
 
33
37
  """
34
38
 
@@ -36,9 +40,11 @@ class DEQueue[D]:
36
40
 
37
41
  def __init__(self, *dss: Iterable[D]) -> None:
38
42
  """
39
- :param dss: "Optionally" takes a single iterable to initialize data in FIFO order.
40
- :raises TypeError: When ``dss[0]`` not Iterable.
41
- :raises ValueError: If more than 1 iterable is given.
43
+ :param dss: Takes 0 or 1 iterable parameters. Populates
44
+ queue from the iterable left to right.
45
+ :raises TypeError: When passed a non-iterable parameter.
46
+ :raises ValueError: When more than one parameter is given.
47
+
42
48
  """
43
49
  if (size := len(dss)) > 1:
44
50
  msg = f'DEQueue expects at most 1 argument, got {size}'
@@ -46,6 +52,12 @@ class DEQueue[D]:
46
52
  self._ca = CA(dss[0]) if size == 1 else CA()
47
53
 
48
54
  def __bool__(self) -> bool:
55
+ """
56
+ .. admonition:: Truthiness
57
+
58
+ Queue truthy when non-empty, falsy when empty.
59
+
60
+ """
49
61
  return len(self._ca) > 0
50
62
 
51
63
  def __len__(self) -> int:
@@ -57,9 +69,25 @@ class DEQueue[D]:
57
69
  return self._ca == other._ca
58
70
 
59
71
  def __iter__(self) -> Iterator[D]:
72
+ """
73
+ .. admonition:: Iteration
74
+
75
+ Iterate over current state left to right.
76
+
77
+ :returns: An iterator of the data.
78
+
79
+ """
60
80
  return iter(list(self._ca))
61
81
 
62
82
  def __reversed__(self) -> Iterator[D]:
83
+ """
84
+ .. admonition:: Iteration
85
+
86
+ Iterate over current state right to left.
87
+
88
+ :returns: An iterator of the data.
89
+
90
+ """
63
91
  return reversed(list(self._ca))
64
92
 
65
93
  def __repr__(self) -> str:
@@ -71,57 +99,89 @@ class DEQueue[D]:
71
99
  return '>< ' + ' | '.join(map(str, self)) + ' ><'
72
100
 
73
101
  def copy(self) -> 'DEQueue[D]':
74
- """Shallow copy.
102
+ """
103
+ .. admonition:: Shallow copy
104
+
105
+ Make a shallow copy of the queue.
106
+
107
+ :returns: Shallow copy of the ``DEQueue``.
75
108
 
76
- :returns: Shallow copy of the DEQueue.
77
109
  """
78
110
  return DEQueue(self._ca)
79
111
 
80
112
  def pushl(self, *ds: D) -> None:
81
- """Push data onto left side of DEQueue.
113
+ """
114
+ .. admonition:: Push left
115
+
116
+ Push data onto left side of ``DEQueue``.
117
+
118
+ :param ds: Data to be pushed onto ``DEQueue`` from the left.
82
119
 
83
- :param ds: Items to be pushed onto DEQueue from the left.
84
120
  """
85
121
  self._ca.pushl(*ds)
86
122
 
87
123
  def pushr(self, *ds: D) -> None:
88
- """Push data onto right side of DEQueue.
124
+ """
125
+ .. admonition:: Push right
126
+
127
+ Push data onto right side of ``DEQueue``.
128
+
129
+ :param ds: Data to be pushed onto ``DEQueue`` from the right.
89
130
 
90
- :param ds: Items to be pushed onto DEQueue from the right.
91
131
  """
92
132
  self._ca.pushr(*ds)
93
133
 
94
134
  def popl(self) -> MayBe[D]:
95
- """Pop next item from left side DEQueue, if it exists.
135
+ """
136
+ .. admonition:: Pop left
137
+
138
+ Pop next item from left side ``DEQueue``, if it exists.
139
+
140
+ :returns: ``MayBe`` of popped item if queue was not empty,
141
+ empty ``MayBe`` otherwise.
96
142
 
97
- :returns: MayBe of popped item if queue was not empty, empty MayBe otherwise.
98
143
  """
99
144
  if self._ca:
100
145
  return MayBe(self._ca.popl())
101
146
  return MayBe()
102
147
 
103
148
  def popr(self) -> MayBe[D]:
104
- """Pop next item off right side DEQueue, if it exists.
149
+ """
150
+ .. admonition:: Pop right
151
+
152
+ Pop next item off right side ''DEQueue``, if it exists.
153
+
154
+ :returns: ``MayBe`` of popped item if queue was not empty,
155
+ empty ``MayBe`` otherwise.
105
156
 
106
- :returns: MayBe of popped item if queue was not empty, empty MayBe otherwise.
107
157
  """
108
158
  if self._ca:
109
159
  return MayBe(self._ca.popr())
110
160
  return MayBe()
111
161
 
112
162
  def peakl(self) -> MayBe[D]:
113
- """Peak left side of DEQueue. Does not consume item.
163
+ """
164
+ .. admonition:: Peak left
165
+
166
+ Peak left side of ``DEQueue``. Does not consume item.
167
+
168
+ :returns: ``MayBe`` of leftmost item if queue not empty,
169
+ empty ``MayBe`` otherwise.
114
170
 
115
- :returns: MayBe of leftmost item if queue not empty, empty MayBe otherwise.
116
171
  """
117
172
  if self._ca:
118
173
  return MayBe(self._ca[0])
119
174
  return MayBe()
120
175
 
121
176
  def peakr(self) -> MayBe[D]:
122
- """Peak right side of DEQueue. Does not consume item.
177
+ """
178
+ .. admonition:: Peak right
179
+
180
+ Peak right side of ``DEQueue``. Does not consume item.
181
+
182
+ :returns: ``MayBe`` of rightmost item if queue not empty,
183
+ empty ``MayBe`` otherwise.
123
184
 
124
- :returns: MayBe of rightmost item if queue not empty, empty MayBe otherwise.
125
185
  """
126
186
  if self._ca:
127
187
  return MayBe(self._ca[-1])
@@ -133,11 +193,16 @@ class DEQueue[D]:
133
193
  def foldl[L](self, f: Callable[[L, D], L], start: L) -> MayBe[L]: ...
134
194
 
135
195
  def foldl[L](self, f: Callable[[L, D], L], start: L | None = None) -> MayBe[L]:
136
- """Reduces DEQueue left to right.
196
+ """
197
+ .. admonition:: Fold left
198
+
199
+ Reduce ``DEQueue`` left to right.
137
200
 
138
201
  :param f: Reducing function, first argument is for accumulator.
139
202
  :param start: Optional starting value.
140
- :returns: MayBe of reduced value with f, empty MayBe if queue empty and no starting value given.
203
+ :returns: ``MayBe`` of reduced value with f, empty ``MayBe`` if
204
+ queue empty and no starting value given.
205
+
141
206
  """
142
207
  if start is None:
143
208
  if not self._ca:
@@ -151,11 +216,16 @@ class DEQueue[D]:
151
216
  def foldr[R](self, f: Callable[[D, R], R], start: R) -> MayBe[R]: ...
152
217
 
153
218
  def foldr[R](self, f: Callable[[D, R], R], start: R | None = None) -> MayBe[R]:
154
- """Reduces DEQueue right to left.
219
+ """
220
+ .. admonition:: Fold right
221
+
222
+ Reduce ``DEQueue`` right to left.
155
223
 
156
224
  :param f: Reducing function, second argument is for accumulator.
157
225
  :param start: Optional starting value.
158
- :returns: MayBe of reduced value with f, empty MayBe if queue empty and no starting value given.
226
+ :returns: ``MayBe`` of reduced value with f, empty ``MayBe`` if
227
+ queue empty and no starting value given.
228
+
159
229
  """
160
230
  if start is None:
161
231
  if not self._ca:
@@ -164,22 +234,31 @@ class DEQueue[D]:
164
234
  return MayBe(self._ca.foldr(f, start))
165
235
 
166
236
  def map[U](self, f: Callable[[D], U]) -> 'DEQueue[U]':
167
- """Map left to right.
237
+ """
238
+ .. admonition:: Map
239
+
240
+ Map left to right.
168
241
 
169
- .. tip::
242
+ .. tip::
170
243
 
171
- Order map done does not matter if ``f`` is pure.
244
+ Order map done does not matter if ``f`` is pure.
172
245
 
173
246
  :param f: Function to map over queue.
174
- :returns: New DEQueue instance, retain original order.
247
+ :returns: New ``DEQueue`` instance, retain original order.
248
+
175
249
  """
176
250
  return DEQueue(map(f, self._ca))
177
251
 
178
252
 
179
253
  def de_queue[D](*ds: D) -> DEQueue[D]:
180
- """DEQueue factory function.
254
+ """
255
+ .. admonition:: Create DEQueue
256
+
257
+ Factory function to create a ``DEQueue``
258
+ instance from the function's arguments.
259
+
260
+ :param ds: Initial data to be pushed on right to left.
261
+ :returns: A new ``DEQueue`` instance.
181
262
 
182
- :param ds: Initial items as if pushed on from right to left.
183
- :returns: DEQueue with items initialized in FIFO order.
184
263
  """
185
264
  return DEQueue(ds)
@@ -0,0 +1,31 @@
1
+ from collections.abc import Callable, Iterable, Iterator
2
+ from pythonic_fp.fptools.maybe import MayBe
3
+ from typing import overload
4
+
5
+ __all__ = ['DEQueue', 'de_queue']
6
+
7
+ class DEQueue[D]:
8
+ def __init__(self, *dss: Iterable[D]) -> None: ...
9
+ def __bool__(self) -> bool: ...
10
+ def __len__(self) -> int: ...
11
+ def __eq__(self, other: object) -> bool: ...
12
+ def __iter__(self) -> Iterator[D]: ...
13
+ def __reversed__(self) -> Iterator[D]: ...
14
+ def copy(self) -> DEQueue[D]: ...
15
+ def pushl(self, *ds: D) -> None: ...
16
+ def pushr(self, *ds: D) -> None: ...
17
+ def popl(self) -> MayBe[D]: ...
18
+ def popr(self) -> MayBe[D]: ...
19
+ def peakl(self) -> MayBe[D]: ...
20
+ def peakr(self) -> MayBe[D]: ...
21
+ @overload
22
+ def foldl[L](self, f: Callable[[D, D], D]) -> MayBe[D]: ...
23
+ @overload
24
+ def foldl[L](self, f: Callable[[L, D], L], start: L) -> MayBe[L]: ...
25
+ @overload
26
+ def foldr[R](self, f: Callable[[D, D], D]) -> MayBe[D]: ...
27
+ @overload
28
+ def foldr[R](self, f: Callable[[D, R], R], start: R) -> MayBe[R]: ...
29
+ def map[U](self, f: Callable[[D], U]) -> DEQueue[U]: ...
30
+
31
+ def de_queue[D](*ds: D) -> DEQueue[D]: ...
@@ -1,4 +1,4 @@
1
- # Copyright 2023-2024 Geoffrey R. Scheller
1
+ # Copyright 2023-2026 Geoffrey R. Scheller
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -21,14 +21,17 @@ __all__ = ['FIFOQueue', 'fifo_queue']
21
21
 
22
22
 
23
23
  class FIFOQueue[D]:
24
- """Stateful First-In-First-Out (FIFO) Queue data structure.
24
+ """
25
+ .. admonition:: FIFOQueue
26
+
27
+ Stateful First-In-First-Out (FIFO) Queue data structure.
25
28
 
26
- - O(1) pops
27
- - O(1) amortized pushes
28
- - O(1) length determination
29
- - in a Boolean context, truthy if not empty, falsy if empty
30
- - will automatically increase storage capacity when needed
31
- - neither indexable nor sliceable by design
29
+ - O(1) pops
30
+ - O(1) amortized pushes
31
+ - O(1) length determination
32
+ - in a Boolean context, truthy if not empty, falsy if empty
33
+ - will automatically increase storage capacity when needed
34
+ - neither indexable nor sliceable by design
32
35
 
33
36
  """
34
37
 
@@ -36,8 +39,11 @@ class FIFOQueue[D]:
36
39
 
37
40
  def __init__(self, *dss: Iterable[D]) -> None:
38
41
  """
39
- :param dss: Takes 1 or 0 iterables, initializes items in natural FIFO order.
40
- :raises ValueError: If more than 1 iterable is given.
42
+ :param dss: Takes 0 or 1 iterable parameters. Populates
43
+ queue from the iterable in FIFO order.
44
+ :raises TypeError: When passed a non-iterable parameter.
45
+ :raises ValueError: When more than one parameter is given.
46
+
41
47
  """
42
48
  if (size := len(dss)) > 1:
43
49
  msg = f'FIFOQueue expects at most 1 iterable argument, got {size}'
@@ -45,6 +51,12 @@ class FIFOQueue[D]:
45
51
  self._ca = CA(dss[0]) if size == 1 else CA()
46
52
 
47
53
  def __bool__(self) -> bool:
54
+ """
55
+ .. admonition:: Truthiness
56
+
57
+ ``FIFOQueue`` truthy when non-empty, falsy when empty.
58
+
59
+ """
48
60
  return len(self._ca) > 0
49
61
 
50
62
  def __len__(self) -> int:
@@ -56,6 +68,14 @@ class FIFOQueue[D]:
56
68
  return self._ca == other._ca
57
69
 
58
70
  def __iter__(self) -> Iterator[D]:
71
+ """
72
+ .. admonition:: Iteration
73
+
74
+ Iterate over current state in natural FIFO order.
75
+
76
+ :returns: An iterator of the data.
77
+
78
+ """
59
79
  return iter(list(self._ca))
60
80
 
61
81
  def __repr__(self) -> str:
@@ -67,41 +87,64 @@ class FIFOQueue[D]:
67
87
  return '<< ' + ' < '.join(map(str, self)) + ' <<'
68
88
 
69
89
  def copy(self) -> 'FIFOQueue[D]':
70
- """Shallow copy.
90
+ """
91
+ .. admonition:: Shallow copy
92
+
93
+ Make a shallow copy of the ``FIFOQueue``.
94
+
95
+ :returns: Shallow copy of the ``FIFOQueue``.
71
96
 
72
- :returns: Shallow copy of the FIFOQueue.
73
97
  """
74
98
  return FIFOQueue(self._ca)
75
99
 
76
100
  def push(self, *ds: D) -> None:
77
- """Push items onto FIFOQueue.
101
+ """
102
+ .. admonition:: Push
103
+
104
+ Push data items onto ``FIFOQueue``.
105
+
106
+ :param ds: Items to be pushed onto ''FIFOQueue''.
78
107
 
79
- :param ds: Items to be pushed onto FIFOQueue.
80
108
  """
81
109
  self._ca.pushr(*ds)
82
110
 
83
111
  def pop(self) -> MayBe[D]:
84
- """Pop oldest data item off of FIFOQueue.
112
+ """
113
+ .. admonition:: Pop
114
+
115
+ Pop oldest data item off of ``FIFOQueue``.
116
+
117
+ :returns: ``MayBe`` of popped data item if ``FIFOQueue``
118
+ was not empty, empty ``MayBe`` otherwise.
85
119
 
86
- :returns: MayBe of popped data item if queue was not empty, empty MayBe otherwise.
87
120
  """
88
121
  if self._ca:
89
122
  return MayBe(self._ca.popl())
90
123
  return MayBe()
91
124
 
92
125
  def peak_last_in(self) -> MayBe[D]:
93
- """Peak at newest item on queue.
126
+ """
127
+ .. admonition:: Peak last
128
+
129
+ Peak at newest item on ``FIFOQueue``.
130
+
131
+ :returns: ``MayBe`` of newest item on ``FIFOQueue``,
132
+ empty ``MayBe`` if ``FIFOQueue`` empty.
94
133
 
95
- :returns: MayBe of newest item on queue, empty MayBe if queue empty.
96
134
  """
97
135
  if self._ca:
98
136
  return MayBe(self._ca[-1])
99
137
  return MayBe()
100
138
 
101
139
  def peak_next_out(self) -> MayBe[D]:
102
- """Peak at oldest data item on queue.
140
+ """
141
+ .. admonition:: Peak next out
142
+
143
+ Peak at oldest data item on ``FIFOQueue``.
144
+
145
+ :returns: ``MayBe`` of oldest item on ``FIFOQueue``,
146
+ empty ``MayBe`` if ``FIFOueue`` empty.
103
147
 
104
- :returns: MayBe of oldest item on queue, empty MayBe if queue empty.
105
148
  """
106
149
  if self._ca:
107
150
  return MayBe(self._ca[0])
@@ -113,11 +156,16 @@ class FIFOQueue[D]:
113
156
  def fold[T](self, f: Callable[[T, D], T], start: T) -> MayBe[T]: ...
114
157
 
115
158
  def fold[T](self, f: Callable[[T, D], T], start: T | None = None) -> MayBe[T]:
116
- """Reduces FIFOQueue in natural FIFO Order, oldest to newest.
159
+ """
160
+ .. admonition:: Fold
161
+
162
+ Reduces ``FIFOQueue`` in natural FIFO Order, oldest to newest.
117
163
 
118
164
  :param f: Reducing function, first argument is for accumulator.
119
165
  :param start: Optional starting value.
120
- :returns: MayBe of reduced value, empty MayBe if queue empty and no starting value given.
166
+ :returns: ``MayBe`` of reduced value, empty ``MayBe`` if ``FIFOQueue``
167
+ empty and no starting value given.
168
+
121
169
  """
122
170
  if start is None:
123
171
  if not self._ca:
@@ -126,18 +174,27 @@ class FIFOQueue[D]:
126
174
  return MayBe(self._ca.foldl(f, start))
127
175
 
128
176
  def map[U](self, f: Callable[[D], U]) -> 'FIFOQueue[U]':
129
- """Map f over the FIFOQueue, retain original order.
177
+ """
178
+ .. admonition:: Map
179
+
180
+ Map ``f`` over the ``FIFOQueue``, retain original order.
181
+
182
+ :param f: Function to map over ``FIFOQueue``.
183
+ :returns: New ``FIFOQueue`` instance.
130
184
 
131
- :param f: Function to map over queue.
132
- :returns: New FIFOQueue instance.
133
185
  """
134
186
  return FIFOQueue(map(f, self._ca))
135
187
 
136
188
 
137
189
  def fifo_queue[D](*ds: D) -> FIFOQueue[D]:
138
- """FIFOQueue factory function.
190
+ """
191
+ .. admonition:: Create FIFOQueue
192
+
193
+ Factory function to create an ``FIFOQueue``
194
+ instance from the function's arguments.
195
+
196
+ :param ds: Initial data to be pushed on in FIFO order.
197
+ :returns: New ``FIFOQueue`` instance.
139
198
 
140
- :param ds: Initial items pushed on in FIFO order.
141
- :returns: FIFOQueue with initialized items from ``ds``.
142
199
  """
143
200
  return FIFOQueue(ds)
@@ -0,0 +1,24 @@
1
+ from collections.abc import Callable, Iterable, Iterator
2
+ from pythonic_fp.fptools.maybe import MayBe
3
+ from typing import overload
4
+
5
+ __all__ = ['FIFOQueue', 'fifo_queue']
6
+
7
+ class FIFOQueue[D]:
8
+ def __init__(self, *dss: Iterable[D]) -> None: ...
9
+ def __bool__(self) -> bool: ...
10
+ def __len__(self) -> int: ...
11
+ def __eq__(self, other: object) -> bool: ...
12
+ def __iter__(self) -> Iterator[D]: ...
13
+ def copy(self) -> FIFOQueue[D]: ...
14
+ def push(self, *ds: D) -> None: ...
15
+ def pop(self) -> MayBe[D]: ...
16
+ def peak_last_in(self) -> MayBe[D]: ...
17
+ def peak_next_out(self) -> MayBe[D]: ...
18
+ @overload
19
+ def fold[T](self, f: Callable[[D, D], D]) -> MayBe[D]: ...
20
+ @overload
21
+ def fold[T](self, f: Callable[[T, D], T], start: T) -> MayBe[T]: ...
22
+ def map[U](self, f: Callable[[D], U]) -> FIFOQueue[U]: ...
23
+
24
+ def fifo_queue[D](*ds: D) -> FIFOQueue[D]: ...
@@ -1,4 +1,4 @@
1
- # Copyright 2023-2024 Geoffrey R. Scheller
1
+ # Copyright 2023-2026 Geoffrey R. Scheller
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -22,22 +22,28 @@ __all__ = ['LIFOQueue', 'lifo_queue']
22
22
 
23
23
 
24
24
  class LIFOQueue[D]:
25
- """Stateful Last-In-First-Out (LIFO) Queue data structure.
25
+ """
26
+ .. admonition:: LIFOQueue
27
+
28
+ Stateful Last-In-First-Out (LIFO) Queue data structure.
26
29
 
27
- - O(1) pops
28
- - O(1) amortized pushes
29
- - O(1) length determination
30
- - in a Boolean context, true if not empty, false if empty
31
- - will automatically increase storage capacity when needed
32
- - neither indexable nor sliceable by design
30
+ - O(1) pops
31
+ - O(1) amortized pushes
32
+ - O(1) length determination
33
+ - in a Boolean context, true if not empty, false if empty
34
+ - will automatically increase storage capacity when needed
35
+ - neither indexable nor sliceable by design
33
36
 
34
37
  """
35
38
  __slots__ = ('_ca',)
36
39
 
37
40
  def __init__(self, *dss: Iterable[D]) -> None:
38
41
  """
39
- :param dss: Takes 1 or 0 iterables, initializes data in natural LIFO order.
40
- :raises ValueError: If more than 1 iterable is given.
42
+ :param dss: Takes 0 or 1 iterable parameters. Populates
43
+ queue from the iterable in LIFO order.
44
+ :raises TypeError: When passed a non-iterable parameter.
45
+ :raises ValueError: When more than one parameter is given.
46
+
41
47
  """
42
48
  if (size := len(dss)) > 1:
43
49
  msg = f'LIFOQueue expects at most 1 iterable argument, got {size}'
@@ -45,6 +51,12 @@ class LIFOQueue[D]:
45
51
  self._ca = CA(dss[0]) if size == 1 else CA()
46
52
 
47
53
  def __bool__(self) -> bool:
54
+ """
55
+ .. admonition:: Truthiness
56
+
57
+ ``LIFOQueue`` truthy when non-empty, falsy when empty.
58
+
59
+ """
48
60
  return len(self._ca) > 0
49
61
 
50
62
  def __len__(self) -> int:
@@ -56,6 +68,14 @@ class LIFOQueue[D]:
56
68
  return self._ca == other._ca
57
69
 
58
70
  def __iter__(self) -> Iterator[D]:
71
+ """
72
+ .. admonition:: Iteration
73
+
74
+ Iterate over current state in natural LIFO order.
75
+
76
+ :returns: Iterator of the data.
77
+
78
+ """
59
79
  return reversed(list(self._ca))
60
80
 
61
81
  def __repr__(self) -> str:
@@ -67,32 +87,46 @@ class LIFOQueue[D]:
67
87
  return '|| ' + ' > '.join(map(str, self)) + ' ><'
68
88
 
69
89
  def copy(self) -> 'LIFOQueue[D]':
70
- """Shallow copy.
90
+ """
91
+ .. admonition:: Shallow copy
92
+
93
+ Make a shallow copy of the ``LIFOQueue``.
94
+
95
+ :returns: Shallow copy of the ``LIFOQueue``.
71
96
 
72
- :returns: Shallow copy of the LIFOQueue.
73
97
  """
74
98
  return LIFOQueue(reversed(self._ca))
75
99
 
76
100
  def push(self, *ds: D) -> None:
77
101
  """Push items onto LIFOQueue.
78
102
 
79
- :param ds: Items to be pushed onto LIFOQueue.
103
+ :param ds: Items to be pushed onto ``LIFOQueue``.
104
+
80
105
  """
81
106
  self._ca.pushr(*ds)
82
107
 
83
108
  def pop(self) -> MayBe[D]:
84
- """Pop newest data item off of LIFOQueue.
109
+ """
110
+ .. admonition:: Pop
111
+
112
+ Pop newest data item off of ``LIFOQueue``.
113
+
114
+ :returns: ``MayBe`` of popped data item if ``LIFOQueue``
115
+ was not empty, empty `MayBe` otherwise.
85
116
 
86
- :returns: MayBe of popped item if queue was not empty, empty MayBe otherwise.
87
117
  """
88
118
  if self._ca:
89
119
  return MayBe(self._ca.popr())
90
120
  return MayBe()
91
121
 
92
122
  def peak(self) -> MayBe[D]:
93
- """Peak at newest item on queue.
123
+ """
124
+ .. admonition:: Peak last
125
+
126
+ Peak at newest item on ``LIFOQueue``.
127
+
128
+ :returns: ``MayBe`` of newest item on queue, empty ``MayBe`` if queue empty.
94
129
 
95
- :returns: MayBe of newest item on queue, empty MayBe if queue empty.
96
130
  """
97
131
  if self._ca:
98
132
  return MayBe(self._ca[-1])
@@ -104,11 +138,16 @@ class LIFOQueue[D]:
104
138
  def fold[T](self, f: Callable[[T, D], T], start: T) -> MayBe[T]: ...
105
139
 
106
140
  def fold[T](self, f: Callable[[T, D], T], start: T | None = None) -> MayBe[T]:
107
- """Reduces LIFOQUEUE in natural LIFO Order, newest to oldest.
141
+ """
142
+ .. admonition:: Fold
143
+
144
+ Reduces ``LIFOQUEUE`` in natural LIFO Order, newest to oldest.
108
145
 
109
146
  :param f: Reducing function, first argument is for accumulator.
110
147
  :param start: Optional starting value.
111
- :returns: MayBe of reduced value, empty MayBe if queue empty and no starting value given.
148
+ :returns: ``MayBe`` of reduced value, empty ``MayBe`` if ``LIFOQueue``
149
+ empty and no starting value given.
150
+
112
151
  """
113
152
  if start is None:
114
153
  if not self._ca:
@@ -117,18 +156,27 @@ class LIFOQueue[D]:
117
156
  return MayBe(self._ca.foldr(swap(f), start))
118
157
 
119
158
  def map[U](self, f: Callable[[D], U]) -> 'LIFOQueue[U]':
120
- """Map f over the LIFOQueue, retain original order.
159
+ """
160
+ .. admonition:: Map
161
+
162
+ Map ``f`` over the ``LIFOQueue``, retain original order.
163
+
164
+ :param f: Function to map over ``LIFOQueue``.
165
+ :returns: New ``LIFOQueue`` instance.
121
166
 
122
- :param f: Function to map over queue.
123
- :returns: New LIFOQueue instance.
124
167
  """
125
168
  return LIFOQueue(reversed(CA(map(f, reversed(self._ca)))))
126
169
 
127
170
 
128
171
  def lifo_queue[D](*ds: D) -> LIFOQueue[D]:
129
- """LIFOQueue factory function.
172
+ """
173
+ .. admonition:: Create LIFOQueue
174
+
175
+ Factory function to create an ``LIFOQUEUE``
176
+ instance from the function's arguments.
177
+
178
+ :param ds: Items pushed onto queue in LIFO order.
179
+ :returns: New ``LIFOQueue`` instance.
130
180
 
131
- :param ds: Initial items pushed on in LIFO order.
132
- :returns: LIFOQueue with initialized items from ``ds``.
133
181
  """
134
182
  return LIFOQueue(ds)
@@ -0,0 +1,23 @@
1
+ from collections.abc import Callable, Iterable, Iterator
2
+ from pythonic_fp.fptools.maybe import MayBe
3
+ from typing import overload
4
+
5
+ __all__ = ['LIFOQueue', 'lifo_queue']
6
+
7
+ class LIFOQueue[D]:
8
+ def __init__(self, *dss: Iterable[D]) -> None: ...
9
+ def __bool__(self) -> bool: ...
10
+ def __len__(self) -> int: ...
11
+ def __eq__(self, other: object) -> bool: ...
12
+ def __iter__(self) -> Iterator[D]: ...
13
+ def copy(self) -> LIFOQueue[D]: ...
14
+ def push(self, *ds: D) -> None: ...
15
+ def pop(self) -> MayBe[D]: ...
16
+ def peak(self) -> MayBe[D]: ...
17
+ @overload
18
+ def fold[T](self, f: Callable[[D, D], D]) -> MayBe[D]: ...
19
+ @overload
20
+ def fold[T](self, f: Callable[[T, D], T], start: T) -> MayBe[T]: ...
21
+ def map[U](self, f: Callable[[D], U]) -> LIFOQueue[U]: ...
22
+
23
+ def lifo_queue[D](*ds: D) -> LIFOQueue[D]: ...
@@ -1,25 +1,25 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonic-fp-queues
3
- Version: 5.1.0
3
+ Version: 5.1.2
4
4
  Summary: Queues
5
5
  Keywords: queue,fifo,lifo,dqueue
6
6
  Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
7
- Requires-Python: >=3.12
7
+ Requires-Python: >=3.13
8
8
  Description-Content-Type: text/x-rst
9
9
  Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: Framework :: Pytest
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Operating System :: OS Independent
14
- Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
15
  Classifier: Typing :: Typed
16
16
  License-File: LICENSE
17
- Requires-Dist: pythonic-fp-circulararray>=6.0.0
18
- Requires-Dist: pythonic-fp-fptools>=5.1.2
17
+ Requires-Dist: pythonic-fp-circulararray>=6.0.4
18
+ Requires-Dist: pythonic-fp-fptools>=5.2.0
19
19
  Requires-Dist: pytest>=8.4.1 ; extra == "test"
20
20
  Project-URL: Changelog, https://github.com/grscheller/pythonic-fp-queues/blob/main/CHANGELOG.rst
21
- Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/queues/development/build/html/index.html
22
- Project-URL: Homepage, https://github.com/grscheller/pythonic-fp/blob/main/README.md
21
+ Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/projects/queues.html
22
+ Project-URL: Homepage, https://grscheller.github.io/pythonic-fp/
23
23
  Project-URL: Source, https://github.com/grscheller/pythonic-fp-queues
24
24
  Provides-Extra: test
25
25
 
@@ -27,8 +27,8 @@ Pythonic FP - Queues
27
27
  ====================
28
28
 
29
29
  PyPI project
30
- `pythonic-fp.queues
31
- <https://pypi.org/project/pythonic-fp.queues>`_.
30
+ `pythonic-fp-queues
31
+ <https://pypi.org/project/pythonic-fp-queues>`_.
32
32
 
33
33
  +-------------------------+-----------+--------------------------+
34
34
  | module | class | name |
@@ -42,19 +42,23 @@ PyPI project
42
42
 
43
43
  Part of the
44
44
  `pythonic-fp
45
- <https://grscheller.github.io/pythonic-fp/homepage/build/html/index.html>`_
45
+ <https://grscheller.github.io/pythonic-fp/>`_
46
46
  PyPI projects.
47
47
 
48
48
  Documentation
49
49
  -------------
50
50
 
51
+ Documentation and other links for this project are hosted on
52
+ `GitHub Pages
53
+ <https://grscheller.github.io/pythonic-fp/projects/queues.html>`_.
54
+
51
55
  Documentation for this project is hosted on
52
56
  `GitHub Pages
53
- <https://grscheller.github.io/pythonic-fp/queues/development/build/html>`_.
57
+ <https://grscheller.github.io/pythonic-fp-queues/development/html/>`_.
54
58
 
55
59
  Copyright and License
56
60
  ---------------------
57
61
 
58
- Copyright (c) 2023-2025 Geoffrey R. Scheller. Licensed under the Apache
62
+ Copyright (c) 2023-2026 Geoffrey R. Scheller. Licensed under the Apache
59
63
  License, Version 2.0. See the LICENSE file for details.
60
64
 
@@ -0,0 +1,13 @@
1
+ pythonic_fp/queues/__init__.py,sha256=NOkkXOQaHmiemvY4Ke5ZdFJCl3_P3bmV87Xz5Y-R9cU,1028
2
+ pythonic_fp/queues/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pythonic_fp/queues/de.py,sha256=hRFeogJ4XuXRFV4xOpD3mLoNo1jklP4uT5Ilrw-PiJg,7456
4
+ pythonic_fp/queues/de.pyi,sha256=db74UiSLFme25Yhc28Hhw3EKb2GfvU4wNBJtkTlr_e4,1150
5
+ pythonic_fp/queues/fifo.py,sha256=EvZub5bRsW3xqCbREKz8dXIt3heBmzsDOzJQuF6Mm30,5728
6
+ pythonic_fp/queues/fifo.pyi,sha256=19TGU3Qg91hCLo5A-5p9vmREcl38EUWhIAvJZtlb1eA,885
7
+ pythonic_fp/queues/lifo.py,sha256=_uBM9XnZMm-OYEDhAHPdcHBy_C6h2d0B0dTpoXaJ62A,5348
8
+ pythonic_fp/queues/lifo.pyi,sha256=HdJ-t7R2w3VfCT06raCTXespdUZfpBgMepBlcxDvyuk,832
9
+ pythonic_fp/queues/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ pythonic_fp_queues-5.1.2.dist-info/licenses/LICENSE,sha256=IJMkVWQUVy-SonK6SMaMotDQ6Zb-lVi2bUTiGp1GUO8,10774
11
+ pythonic_fp_queues-5.1.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
12
+ pythonic_fp_queues-5.1.2.dist-info/METADATA,sha256=fzVKSB2LG3S9c78klIzZ6zvaH1JT4mfRa6NZzZiD7d0,2350
13
+ pythonic_fp_queues-5.1.2.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- pythonic_fp/queues/__init__.py,sha256=BagRl3n3W-lxxPigkGNFMDFNs8surchki-YNXczrPto,1352
2
- pythonic_fp/queues/de.py,sha256=qHDFe1djYGcDMn1THApsYtAd_iZDnJyrMJK0gHkD2vA,6072
3
- pythonic_fp/queues/fifo.py,sha256=V7kAxqnBBBgheBHbaCo1tyORHJqeVR-HMzWiDdAulbU,4593
4
- pythonic_fp/queues/lifo.py,sha256=HAlSz4eKlVatLXkL6uux_gZXjFwiA4X_btDTAF6PM10,4406
5
- pythonic_fp/queues/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- pythonic_fp_queues-5.1.0.dist-info/licenses/LICENSE,sha256=IJMkVWQUVy-SonK6SMaMotDQ6Zb-lVi2bUTiGp1GUO8,10774
7
- pythonic_fp_queues-5.1.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
8
- pythonic_fp_queues-5.1.0.dist-info/METADATA,sha256=6AAV5vX106ojMsJtRQXGxZHz7ROKCZsghKcpYcuzASo,2282
9
- pythonic_fp_queues-5.1.0.dist-info/RECORD,,