Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

python-asynctools

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-asynctools - pypi Package Compare versions

Comparing version
0.0.1
to
0.0.2
+47
-2
asynctools/__init__.py

@@ -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

[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>"]