python-iterutils 0.1.0__py3-none-any.whl → 0.1.1__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.
- iterutils/__init__.py +47 -4
- {python_iterutils-0.1.0.dist-info → python_iterutils-0.1.1.dist-info}/METADATA +1 -1
- python_iterutils-0.1.1.dist-info/RECORD +7 -0
- python_iterutils-0.1.0.dist-info/RECORD +0 -7
- {python_iterutils-0.1.0.dist-info → python_iterutils-0.1.1.dist-info}/LICENSE +0 -0
- {python_iterutils-0.1.0.dist-info → python_iterutils-0.1.1.dist-info}/WHEEL +0 -0
iterutils/__init__.py
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 1,
|
|
5
|
+
__version__ = (0, 1, 1)
|
|
6
6
|
__all__ = [
|
|
7
|
-
"
|
|
8
|
-
"flatten", "async_flatten", "chunked", "wrap_iter", "wrap_aiter",
|
|
9
|
-
"
|
|
7
|
+
"Return", "Yield", "YieldFrom", "iterable", "async_iterable", "foreach", "async_foreach",
|
|
8
|
+
"through", "async_through", "flatten", "async_flatten", "chunked", "wrap_iter", "wrap_aiter",
|
|
9
|
+
"acc_step", "cut_iter", "run_gen_step", "run_gen_step_iter", "bfs_gen",
|
|
10
10
|
]
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
from abc import ABC, abstractmethod
|
|
14
14
|
from asyncio import to_thread
|
|
15
|
+
from collections import deque
|
|
15
16
|
from collections.abc import (
|
|
16
17
|
AsyncIterable, AsyncIterator, Buffer, Callable, Generator,
|
|
17
18
|
Iterable, Iterator, Sequence,
|
|
@@ -565,3 +566,45 @@ def run_gen_step_iter(
|
|
|
565
566
|
close()
|
|
566
567
|
return process()
|
|
567
568
|
|
|
569
|
+
|
|
570
|
+
@overload
|
|
571
|
+
def bfs_gen[T](
|
|
572
|
+
initial: T,
|
|
573
|
+
/,
|
|
574
|
+
unpack_iterator: Literal[False] = False,
|
|
575
|
+
) -> Generator[T, T | None, None]:
|
|
576
|
+
...
|
|
577
|
+
@overload
|
|
578
|
+
def bfs_gen[T](
|
|
579
|
+
initial: T | Iterator[T],
|
|
580
|
+
/,
|
|
581
|
+
unpack_iterator: Literal[True],
|
|
582
|
+
) -> Generator[T, T | None, None]:
|
|
583
|
+
...
|
|
584
|
+
def bfs_gen[T](
|
|
585
|
+
initial: T | Iterator[T],
|
|
586
|
+
/,
|
|
587
|
+
unpack_iterator: bool = False,
|
|
588
|
+
) -> Generator[T, T | None, None]:
|
|
589
|
+
"""辅助函数,返回生成器,用来简化广度优先遍历
|
|
590
|
+
"""
|
|
591
|
+
dq: deque[T] = deque()
|
|
592
|
+
push, pushmany, pop = dq.append, dq.extend, dq.popleft
|
|
593
|
+
if isinstance(initial, Iterator) and unpack_iterator:
|
|
594
|
+
pushmany(initial)
|
|
595
|
+
else:
|
|
596
|
+
push(initial) # type: ignore
|
|
597
|
+
while dq:
|
|
598
|
+
args: None | T = yield (val := pop())
|
|
599
|
+
if unpack_iterator:
|
|
600
|
+
while args is not None:
|
|
601
|
+
if isinstance(args, Iterator):
|
|
602
|
+
pushmany(args)
|
|
603
|
+
else:
|
|
604
|
+
push(args)
|
|
605
|
+
args = yield val
|
|
606
|
+
else:
|
|
607
|
+
while args is not None:
|
|
608
|
+
push(args)
|
|
609
|
+
args = yield val
|
|
610
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
iterutils/__init__.py,sha256=Wrlg5UDuOta7ixKS3Mh5FT9EZkqKT7sBRXNeujoanDE,18639
|
|
3
|
+
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_iterutils-0.1.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_iterutils-0.1.1.dist-info/METADATA,sha256=DjSEacOQgDGD7CZDcm-uzPLfWz-Gayb5agE0pkZjRUM,1341
|
|
6
|
+
python_iterutils-0.1.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
+
python_iterutils-0.1.1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
iterutils/__init__.py,sha256=m6CldG12romSrteHnbHufKlmbRjzd6LfnsxqrqCETwM,17487
|
|
3
|
-
iterutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_iterutils-0.1.0.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_iterutils-0.1.0.dist-info/METADATA,sha256=a1p4ibqdGfFKWEhsNSv80GJwd3PiNr7JNCmVOBEAb2U,1341
|
|
6
|
-
python_iterutils-0.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
7
|
-
python_iterutils-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|