pythonic-fp.iterables 3.0.0__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.
pythonic_fp/iterables.py
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
# Copyright 2023-2025 Geoffrey R. Scheller
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Module fp.iterables - Iterator related tools
|
|
16
|
+
|
|
17
|
+
Library of iterator related functions and enumerations.
|
|
18
|
+
|
|
19
|
+
- Concatenating and merging iterables
|
|
20
|
+
- Dropping and taking values from iterables
|
|
21
|
+
- Reducing and accumulating iterables
|
|
22
|
+
- Assumptions
|
|
23
|
+
|
|
24
|
+
- iterables are not necessarily iterators
|
|
25
|
+
- at all times iterator protocol is assumed to be followed
|
|
26
|
+
|
|
27
|
+
- all iterators are assumed to be iterable
|
|
28
|
+
- for all iterators ``foo`` we assume ``iter(foo) is foo``
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
__author__ = 'Geoffrey R. Scheller'
|
|
34
|
+
__copyright__ = 'Copyright (c) 2023-2025 Geoffrey R. Scheller'
|
|
35
|
+
__license__ = 'Apache License 2.0'
|
|
36
|
+
|
|
37
|
+
from collections.abc import Callable, Iterable, Iterator
|
|
38
|
+
from enum import auto, Enum
|
|
39
|
+
from typing import cast, Never, TypeVar
|
|
40
|
+
from pythonic_fp.containers.box import Box
|
|
41
|
+
from pythonic_fp.containers.maybe import MayBe as MB
|
|
42
|
+
from pythonic_fp.fptools.function import negate, swap
|
|
43
|
+
from pythonic_fp.fptools.singletons import NoValue
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
'FM',
|
|
47
|
+
'concat',
|
|
48
|
+
'merge',
|
|
49
|
+
'exhaust',
|
|
50
|
+
'drop',
|
|
51
|
+
'drop_while',
|
|
52
|
+
'take',
|
|
53
|
+
'take_while',
|
|
54
|
+
'take_split',
|
|
55
|
+
'take_while_split',
|
|
56
|
+
'accumulate',
|
|
57
|
+
'foldl',
|
|
58
|
+
'mb_fold_left',
|
|
59
|
+
'reduce_left',
|
|
60
|
+
'sc_reduce_left',
|
|
61
|
+
'sc_reduce_right',
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
D = TypeVar('D') # Needed only for pdoc documentation generation.
|
|
65
|
+
L = TypeVar('L') # Otherwise, ignored by both MyPy and Python.
|
|
66
|
+
|
|
67
|
+
# Iterate over multiple iterables
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class FM(Enum):
|
|
71
|
+
"""Types of iterable blending,
|
|
72
|
+
|
|
73
|
+
- **CONCAT:** Concatenate first to last
|
|
74
|
+
- **MERGE:** Merge until one is exhausted
|
|
75
|
+
- **EXHAUST:** Merge until all are exhausted
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
CONCAT = auto()
|
|
79
|
+
MERGE = auto()
|
|
80
|
+
EXHAUST = auto()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def concat[D](*iterables: Iterable[D]) -> Iterator[D]:
|
|
84
|
+
"""Sequentially concatenate multiple iterables together.
|
|
85
|
+
|
|
86
|
+
- pure Python version of standard library's ``itertools.chain``
|
|
87
|
+
- iterator sequentially yields each iterable until all are exhausted
|
|
88
|
+
- an infinite iterable will prevent subsequent iterables from yielding any values
|
|
89
|
+
- performant to ``itertools.chain``
|
|
90
|
+
"""
|
|
91
|
+
for iterator in map(lambda x: iter(x), iterables):
|
|
92
|
+
while True:
|
|
93
|
+
try:
|
|
94
|
+
value = next(iterator)
|
|
95
|
+
yield value
|
|
96
|
+
except StopIteration:
|
|
97
|
+
break
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def exhaust[D](*iterables: Iterable[D]) -> Iterator[D]:
|
|
101
|
+
"""Shuffle together multiple iterables until all are exhausted.
|
|
102
|
+
Iterator yields until all iterables are exhausted.
|
|
103
|
+
"""
|
|
104
|
+
iter_list = list(map(lambda x: iter(x), iterables))
|
|
105
|
+
if (num_iters := len(iter_list)) > 0:
|
|
106
|
+
ii = 0
|
|
107
|
+
values = []
|
|
108
|
+
while True:
|
|
109
|
+
try:
|
|
110
|
+
while ii < num_iters:
|
|
111
|
+
values.append(next(iter_list[ii]))
|
|
112
|
+
ii += 1
|
|
113
|
+
yield from values
|
|
114
|
+
ii = 0
|
|
115
|
+
values.clear()
|
|
116
|
+
except StopIteration:
|
|
117
|
+
num_iters -= 1
|
|
118
|
+
if num_iters < 1:
|
|
119
|
+
break
|
|
120
|
+
del iter_list[ii]
|
|
121
|
+
|
|
122
|
+
yield from values
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def merge[D](*iterables: Iterable[D], yield_partials: bool = False) -> Iterator[D]:
|
|
126
|
+
"""Shuffle together the ``iterables`` until one is exhausted.
|
|
127
|
+
|
|
128
|
+
- iterator yields until one of the iterables is exhausted
|
|
129
|
+
- if ``yield_partials`` is true,
|
|
130
|
+
|
|
131
|
+
- yield any unmatched yielded values from other iterables
|
|
132
|
+
- prevents data lose
|
|
133
|
+
|
|
134
|
+
- if any of the iterables are iterators with external references
|
|
135
|
+
"""
|
|
136
|
+
iter_list = list(map(lambda x: iter(x), iterables))
|
|
137
|
+
values = []
|
|
138
|
+
if (num_iters := len(iter_list)) > 0:
|
|
139
|
+
while True:
|
|
140
|
+
try:
|
|
141
|
+
for ii in range(num_iters):
|
|
142
|
+
values.append(next(iter_list[ii]))
|
|
143
|
+
yield from values
|
|
144
|
+
values.clear()
|
|
145
|
+
except StopIteration:
|
|
146
|
+
break
|
|
147
|
+
if yield_partials:
|
|
148
|
+
yield from values
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
## dropping and taking
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def drop[D](iterable: Iterable[D], n: int, /) -> Iterator[D]:
|
|
155
|
+
"""Drop the next ``n`` values from ``iterable``."""
|
|
156
|
+
it = iter(iterable)
|
|
157
|
+
for _ in range(n):
|
|
158
|
+
try:
|
|
159
|
+
next(it)
|
|
160
|
+
except StopIteration:
|
|
161
|
+
break
|
|
162
|
+
return it
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def drop_while[D](iterable: Iterable[D], pred: Callable[[D], bool], /) -> Iterator[D]:
|
|
166
|
+
"""Drop initial values from ``iterable`` while predicate is true."""
|
|
167
|
+
it = iter(iterable)
|
|
168
|
+
while True:
|
|
169
|
+
try:
|
|
170
|
+
value = next(it)
|
|
171
|
+
if not pred(value):
|
|
172
|
+
it = concat((value,), it)
|
|
173
|
+
break
|
|
174
|
+
except StopIteration:
|
|
175
|
+
break
|
|
176
|
+
return it
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def take[D](iterable: Iterable[D], n: int, /) -> Iterator[D]:
|
|
180
|
+
"""Return an iterator of up to ``n`` initial values of an iterable"""
|
|
181
|
+
it = iter(iterable)
|
|
182
|
+
for _ in range(n):
|
|
183
|
+
try:
|
|
184
|
+
value = next(it)
|
|
185
|
+
yield value
|
|
186
|
+
except StopIteration:
|
|
187
|
+
break
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def take_split[D](iterable: Iterable[D], n: int, /) -> tuple[Iterator[D], Iterator[D]]:
|
|
191
|
+
"""Same as take except also return an iterator of the remaining values.
|
|
192
|
+
|
|
193
|
+
- return a tuple of
|
|
194
|
+
|
|
195
|
+
- an iterator of up to ``n`` initial values
|
|
196
|
+
- an iterator of the remaining vales of the ``iterable``
|
|
197
|
+
|
|
198
|
+
- Contract: do not access second iterator until first is exhausted
|
|
199
|
+
"""
|
|
200
|
+
it = iter(iterable)
|
|
201
|
+
itn = take(it, n)
|
|
202
|
+
|
|
203
|
+
return itn, it
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def take_while[D](iterable: Iterable[D], pred: Callable[[D], bool], /) -> Iterator[D]:
|
|
207
|
+
"""Yield values from ``iterable`` while predicate is true.
|
|
208
|
+
|
|
209
|
+
.. warning::
|
|
210
|
+
Risk of value loss if iterable is multiple referenced iterator.
|
|
211
|
+
"""
|
|
212
|
+
it = iter(iterable)
|
|
213
|
+
while True:
|
|
214
|
+
try:
|
|
215
|
+
value = next(it)
|
|
216
|
+
if pred(value):
|
|
217
|
+
yield value
|
|
218
|
+
else:
|
|
219
|
+
break
|
|
220
|
+
except StopIteration:
|
|
221
|
+
break
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def take_while_split[D](
|
|
225
|
+
iterable: Iterable[D], pred: Callable[[D], bool], /
|
|
226
|
+
) -> tuple[Iterator[D], Iterator[D]]:
|
|
227
|
+
"""Yield values from ``iterable`` while ``predicate`` is true.
|
|
228
|
+
|
|
229
|
+
- return a tuple of two iterators
|
|
230
|
+
|
|
231
|
+
- first of initial values where predicate is true, followed by first to fail
|
|
232
|
+
- second of the remaining values of the iterable after first failed value
|
|
233
|
+
|
|
234
|
+
- **Contract:** do not access second iterator until first is exhausted
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
def _take_while(
|
|
238
|
+
it: Iterator[D], pred: Callable[[D], bool], val: Box[D]
|
|
239
|
+
) -> Iterator[D]:
|
|
240
|
+
while True:
|
|
241
|
+
try:
|
|
242
|
+
val.put(next(it))
|
|
243
|
+
if pred(val.get()):
|
|
244
|
+
yield val.pop()
|
|
245
|
+
else:
|
|
246
|
+
break
|
|
247
|
+
except StopIteration:
|
|
248
|
+
break
|
|
249
|
+
|
|
250
|
+
it = iter(iterable)
|
|
251
|
+
value: Box[D] = Box()
|
|
252
|
+
it_pred = _take_while(it, pred, value)
|
|
253
|
+
|
|
254
|
+
return (it_pred, concat(value, it))
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
## reducing and accumulating
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def accumulate[D, L](
|
|
261
|
+
iterable: Iterable[D], f: Callable[[L, D], L], initial: L | NoValue = NoValue(), /
|
|
262
|
+
) -> Iterator[L]:
|
|
263
|
+
"""Returns an iterator of accumulated values.
|
|
264
|
+
|
|
265
|
+
- pure Python version of standard library's ``itertools.accumulate``
|
|
266
|
+
- function ``f`` does not default to addition (for typing flexibility)
|
|
267
|
+
- begins accumulation with an optional ``initial`` value
|
|
268
|
+
"""
|
|
269
|
+
it = iter(iterable)
|
|
270
|
+
try:
|
|
271
|
+
it0 = next(it)
|
|
272
|
+
except StopIteration:
|
|
273
|
+
if initial is NoValue():
|
|
274
|
+
return
|
|
275
|
+
yield cast(L, initial)
|
|
276
|
+
else:
|
|
277
|
+
if initial is not NoValue():
|
|
278
|
+
init = cast(L, initial)
|
|
279
|
+
yield init
|
|
280
|
+
acc = f(init, it0)
|
|
281
|
+
for ii in it:
|
|
282
|
+
yield acc
|
|
283
|
+
acc = f(acc, ii)
|
|
284
|
+
yield acc
|
|
285
|
+
else:
|
|
286
|
+
acc = cast(L, it0) # in this case L = D
|
|
287
|
+
for ii in it:
|
|
288
|
+
yield acc
|
|
289
|
+
acc = f(acc, ii)
|
|
290
|
+
yield acc
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def reduce_left[D](iterable: Iterable[D], f: Callable[[D, D], D], /) -> D | Never:
|
|
294
|
+
"""Fold an iterable left with a function.
|
|
295
|
+
|
|
296
|
+
- traditional FP type order given for function ``f``
|
|
297
|
+
- if iterable empty, ``StopIteration`` exception raised
|
|
298
|
+
- does not catch any exceptions ``f`` may raise
|
|
299
|
+
- never returns if ``iterable`` generates an infinite iterator
|
|
300
|
+
"""
|
|
301
|
+
it = iter(iterable)
|
|
302
|
+
try:
|
|
303
|
+
acc = next(it)
|
|
304
|
+
except StopIteration as exc:
|
|
305
|
+
msg = 'Attemped to reduce an empty iterable.'
|
|
306
|
+
raise StopIteration(msg) from exc
|
|
307
|
+
|
|
308
|
+
for v in it:
|
|
309
|
+
acc = f(acc, v)
|
|
310
|
+
|
|
311
|
+
return acc
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def foldl[D, L](
|
|
315
|
+
iterable: Iterable[D], f: Callable[[L, D], L], initial: L, /
|
|
316
|
+
) -> L | Never:
|
|
317
|
+
"""Folds an iterable left with a function and initial value.
|
|
318
|
+
|
|
319
|
+
- traditional FP type order given for function ``f``
|
|
320
|
+
- does not catch any exceptions ``f`` may raise
|
|
321
|
+
- like builtin ``sum`` for Python >=3.8 except
|
|
322
|
+
|
|
323
|
+
- not restricted to ``__add__`` for the folding function
|
|
324
|
+
- initial value required, does not default to ``0`` for initial value
|
|
325
|
+
- handles non-numeric data just find
|
|
326
|
+
|
|
327
|
+
- never returns if ``iterable`` generates an infinite iterator
|
|
328
|
+
"""
|
|
329
|
+
acc = initial
|
|
330
|
+
for v in iterable:
|
|
331
|
+
acc = f(acc, v)
|
|
332
|
+
return acc
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def mb_fold_left[L, D](
|
|
336
|
+
iterable: Iterable[D], f: Callable[[L, D], L], initial: L | NoValue = NoValue()
|
|
337
|
+
) -> MB[L]:
|
|
338
|
+
"""Folds an iterable left with optional initial value.
|
|
339
|
+
|
|
340
|
+
- traditional FP type order given for function ``f``
|
|
341
|
+
- when an initial value is not given then ``~L = ~D``
|
|
342
|
+
- if iterable empty and no ``initial`` value given, return ``MB()``
|
|
343
|
+
- never returns if iterable generates an infinite iterator
|
|
344
|
+
"""
|
|
345
|
+
acc: L
|
|
346
|
+
it = iter(iterable)
|
|
347
|
+
if initial is NoValue():
|
|
348
|
+
try:
|
|
349
|
+
acc = cast(L, next(it)) # in this case L = D
|
|
350
|
+
except StopIteration:
|
|
351
|
+
return MB()
|
|
352
|
+
else:
|
|
353
|
+
acc = cast(L, initial)
|
|
354
|
+
|
|
355
|
+
for v in it:
|
|
356
|
+
try:
|
|
357
|
+
acc = f(acc, v)
|
|
358
|
+
except Exception:
|
|
359
|
+
return MB()
|
|
360
|
+
|
|
361
|
+
return MB(acc)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def sc_reduce_left[D](
|
|
365
|
+
iterable: Iterable[D],
|
|
366
|
+
f: Callable[[D, D], D],
|
|
367
|
+
/,
|
|
368
|
+
start: Callable[[D], bool] = (lambda d: True),
|
|
369
|
+
stop: Callable[[D], bool] = (lambda d: False),
|
|
370
|
+
include_start: bool = True,
|
|
371
|
+
include_stop: bool = True,
|
|
372
|
+
) -> tuple[MB[D], Iterator[D]]:
|
|
373
|
+
"""Short circuit version of a left reduce. Useful for infinite or iterables.
|
|
374
|
+
|
|
375
|
+
- Behavior for default arguments will
|
|
376
|
+
|
|
377
|
+
- left reduce finite iterable
|
|
378
|
+
- start folding immediately
|
|
379
|
+
- continue folding until end (of a possibly infinite iterable)
|
|
380
|
+
|
|
381
|
+
- Callable ``start`` delays starting the left reduce
|
|
382
|
+
- Callable ``stop`` prematurely stop the left reduce
|
|
383
|
+
"""
|
|
384
|
+
it_start = drop_while(iterable, negate(start))
|
|
385
|
+
if not include_start:
|
|
386
|
+
try:
|
|
387
|
+
next(it_start)
|
|
388
|
+
except StopIteration:
|
|
389
|
+
pass
|
|
390
|
+
it_reduce, it_rest = take_while_split(it_start, negate(stop))
|
|
391
|
+
mb_reduced = mb_fold_left(it_reduce, f)
|
|
392
|
+
if include_stop:
|
|
393
|
+
if mb_reduced:
|
|
394
|
+
try:
|
|
395
|
+
last = next(it_rest)
|
|
396
|
+
mb_reduced = MB(f(mb_reduced.get(), last))
|
|
397
|
+
except StopIteration:
|
|
398
|
+
pass
|
|
399
|
+
else:
|
|
400
|
+
try:
|
|
401
|
+
last = next(it_rest)
|
|
402
|
+
mb_reduced = MB(last)
|
|
403
|
+
except StopIteration:
|
|
404
|
+
pass
|
|
405
|
+
|
|
406
|
+
return (mb_reduced, it_rest)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def sc_reduce_right[D](
|
|
410
|
+
iterable: Iterable[D],
|
|
411
|
+
f: Callable[[D, D], D],
|
|
412
|
+
/,
|
|
413
|
+
start: Callable[[D], bool] = (lambda d: False),
|
|
414
|
+
stop: Callable[[D], bool] = (lambda d: False),
|
|
415
|
+
include_start: bool = True,
|
|
416
|
+
include_stop: bool = True,
|
|
417
|
+
) -> tuple[MB[D], Iterator[D]]:
|
|
418
|
+
"""Short circuit version of a right reduce. Useful for infinite or
|
|
419
|
+
non-reversible iterables.
|
|
420
|
+
|
|
421
|
+
- Behavior for default arguments will
|
|
422
|
+
|
|
423
|
+
- right reduce finite iterable
|
|
424
|
+
- start reducing at end (of a possibly infinite iterable)
|
|
425
|
+
- continue reducing right until beginning
|
|
426
|
+
|
|
427
|
+
- Callable ``start`` prematurely starts the right reduce
|
|
428
|
+
- Callable ``stop`` prematurely stops the right reduce
|
|
429
|
+
"""
|
|
430
|
+
it_start, it_rest = take_while_split(iterable, negate(start))
|
|
431
|
+
l1 = list(it_start)
|
|
432
|
+
if include_start:
|
|
433
|
+
try:
|
|
434
|
+
begin = next(it_rest)
|
|
435
|
+
except StopIteration:
|
|
436
|
+
pass
|
|
437
|
+
else:
|
|
438
|
+
l1.append(begin)
|
|
439
|
+
|
|
440
|
+
l1.reverse()
|
|
441
|
+
it_reduce, it_stop = take_while_split(l1, negate(stop))
|
|
442
|
+
|
|
443
|
+
mb_reduced = mb_fold_left(it_reduce, swap(f))
|
|
444
|
+
if include_stop:
|
|
445
|
+
try:
|
|
446
|
+
end = next(it_stop)
|
|
447
|
+
except StopIteration:
|
|
448
|
+
pass
|
|
449
|
+
else:
|
|
450
|
+
if mb_reduced:
|
|
451
|
+
mb_reduced = MB(f(end, mb_reduced.get()))
|
|
452
|
+
else:
|
|
453
|
+
mb_reduced = MB(end)
|
|
454
|
+
|
|
455
|
+
return (mb_reduced, it_rest)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pythonic-fp.iterables
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Module fp.iterables - Iterator related tools
|
|
5
|
+
Keywords: iterables,iterators
|
|
6
|
+
Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Framework :: Pytest
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: pythonic-fp.circulararray>=5.0.0
|
|
18
|
+
Requires-Dist: pythonic-fp.containers >=2.0.0
|
|
19
|
+
Requires-Dist: pythonic-fp.fptools >=3.0.0
|
|
20
|
+
Project-URL: Changelog, https://grscheller.github.io/pythonic-fp-iterables/html/changelog.html
|
|
21
|
+
Project-URL: Documentation, https://grscheller.github.io/pythonic-fp-iterables/html/
|
|
22
|
+
Project-URL: Homepage, https://github.com/grscheller/pythonic-fp/blob/main/README.md
|
|
23
|
+
Project-URL: Source, https://github.com/grscheller/pythonic-fp-iterables
|
|
24
|
+
|
|
25
|
+
# Pythonic FP - Tools for iterables
|
|
26
|
+
|
|
27
|
+
PyPI project
|
|
28
|
+
[pythonic-fp.iterators](https://pypi.org/project/pythonic-fp.iterables/)
|
|
29
|
+
implementing a Python package of tools for iterables and iterators.
|
|
30
|
+
|
|
31
|
+
- Concatenating and merging iterables
|
|
32
|
+
- Dropping and taking values from iterables
|
|
33
|
+
- Reducing and accumulating iterables
|
|
34
|
+
- Assumptions
|
|
35
|
+
- iterables are not necessarily iterators
|
|
36
|
+
- at all times iterator protocol is assumed to be followed
|
|
37
|
+
- all iterators are assumed to be iterable
|
|
38
|
+
- for all iterators `my_iter` we assume `iter(my_iter) is my_iter`
|
|
39
|
+
|
|
40
|
+
This PyPI project is part of of the grscheller
|
|
41
|
+
[pythonic-fp namespace projects](https://github.com/grscheller/pythonic-fp/blob/main/README.md).
|
|
42
|
+
|
|
43
|
+
## Documentation
|
|
44
|
+
|
|
45
|
+
Documentation hosted on
|
|
46
|
+
[GitHub Pages](https://grscheller.github.io/pythonic-fp-iterables/html).
|
|
47
|
+
|
|
48
|
+
## Copyright and License
|
|
49
|
+
|
|
50
|
+
Copyright (c) 2023-2025 Geoffrey R. Scheller. Licensed under the Apache
|
|
51
|
+
License, Version 2.0. See the LICENSE file for details.
|
|
52
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
pythonic_fp/iterables.py,sha256=Si4a4JcJhrStvpxqe8msaqiskcgrb3D8xJP2oN-6VG8,13194
|
|
2
|
+
pythonic_fp_iterables-3.0.0.dist-info/licenses/LICENSE,sha256=IJMkVWQUVy-SonK6SMaMotDQ6Zb-lVi2bUTiGp1GUO8,10774
|
|
3
|
+
pythonic_fp_iterables-3.0.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
4
|
+
pythonic_fp_iterables-3.0.0.dist-info/METADATA,sha256=9vZd4-jSvYbAXdXXSo6UwZHcLgrSEprn2J6cgyqUkeA,2059
|
|
5
|
+
pythonic_fp_iterables-3.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright (c) 2023-2025 Geoffrey R. Scheller
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|