python-asynctools
Advanced tools
@@ -5,6 +5,6 @@ #!/usr/bin/env python3 | ||
| __author__ = "ChenyangGao <https://chenyanggao.github.io>" | ||
| __version__ = (0, 0, 1) | ||
| __version__ = (0, 0, 2) | ||
| __all__ = [ | ||
| "as_thread", "ensure_async", "ensure_await", "ensure_coroutine", "ensure_aiter", | ||
| "call_as_aiter", "to_list", | ||
| "async_map", "async_filter", "async_reduce", "async_zip", "call_as_aiter", "to_list", | ||
| ] | ||
@@ -108,2 +108,47 @@ | ||
| async def async_map(func, iterable, /, *iterables, threaded: bool = True): | ||
| func = ensure_async(func, threaded=threaded) | ||
| if iterables: | ||
| async for args in async_zip(iterable, *iterables, threaded=threaded): | ||
| yield await func(*args) | ||
| else: | ||
| async for arg in ensure_aiter(iterable, threaded=threaded): | ||
| yield await func(arg) | ||
| async def async_filter(func, iterable, /, threaded: bool = True): | ||
| func = ensure_async(func, threaded=threaded) | ||
| async for arg in ensure_aiter(iterable, threaded=threaded): | ||
| if (await func(arg)): | ||
| yield arg | ||
| async def async_reduce(func, iterable, initial=undefined, /, threaded: bool = True): | ||
| ait = ensure_aiter(iterable, threaded=threaded) | ||
| if initial is undefined: | ||
| try: | ||
| initial = await ait.__anext__() | ||
| except StopAsyncIteration: | ||
| raise TypeError("reduce() of empty iterable with no initial value") | ||
| func = ensure_async(func, threaded=threaded) | ||
| prev = initial | ||
| async for arg in ait: | ||
| prev = await func(prev, arg) | ||
| return prev | ||
| async def async_zip(iterable, /, *iterables, threaded: bool = True): | ||
| iterable = ensure_aiter(iterable, threaded=threaded) | ||
| if iterables: | ||
| fs = (iterable.__anext__, *(ensure_aiter(it, threaded=threaded).__anext__ for it in iterables)) | ||
| try: | ||
| while True: | ||
| yield tuple([await f() for f in fs]) | ||
| except StopAsyncIteration: | ||
| pass | ||
| else: | ||
| async for e in iterable: | ||
| yield e | ||
| async def call_as_aiter( | ||
@@ -110,0 +155,0 @@ func: Callable[[], T] | Callable[[], Awaitable[T]], |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: python-asynctools | ||
| Version: 0.0.1 | ||
| Version: 0.0.2 | ||
| Summary: Python asynchronous tools. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-asynctools |
+1
-1
| [tool.poetry] | ||
| name = "python-asynctools" | ||
| version = "0.0.1" | ||
| version = "0.0.2" | ||
| description = "Python asynchronous tools." | ||
@@ -5,0 +5,0 @@ authors = ["ChenyangGao <wosiwujm@gmail.com>"] |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
9181
21.15%149
33.04%