Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def map(fn: Callable[[T], R], itr: AnyIterable[T]) -> AsyncIterator[R]:
"""
Modify item of a mixed iterable using the given function or coroutine.
Example:
async for response in map(func, data):
...
"""
# todo: queue items eagerly
async for item in iter(itr):
yield await maybe_await(fn(item))
async def starmap(
fn: AnyFunction[R], iterable: AnyIterableIterable[Any]
) -> AsyncIterator[R]:
"""
Yield values from a function using an iterable of iterables for arguments.
Each iterable contained within will be unpacked and consumed before
executing the function or coroutine.
Example:
data = [(1, 1), (1, 1, 1), (2, 2)]
async for value in starmap(operator.add, data):
... # 2, 3, 4
"""
async for itr in iter(iterable):
args = await list(itr)