Skip to content

Async Iterable Helpers

pdum.plumbum.aiterops

Attributes

AsyncMapper module-attribute

AsyncMapper = Callable[[T], Awaitable[U]] | Callable[[T], U]

AsyncPredicate module-attribute

AsyncPredicate = Callable[[T], Awaitable[bool]] | Callable[[T], bool]

T module-attribute

T = TypeVar('T')

U module-attribute

U = TypeVar('U')

V module-attribute

V = TypeVar('V')

__all__ module-attribute

__all__ = [
    "aselect",
    "awhere",
    "aiter",
    "async_iter_operator",
    "AsyncMapper",
    "AsyncPredicate",
    "atake",
    "askip",
    "atake_while",
    "askip_while",
    "adedup",
    "auniq",
    "apermutations",
    "atail",
    "asort",
    "areverse",
    "at",
    "alist",
    "atranspose",
    "abatched",
    "atee",
    "atraverse",
    "agroupby",
    "achain",
    "achain_with",
    "aislice",
    "aizip",
    "anetcat",
    "aenumerate",
    "amap",
    "afilter",
    "acollect",
]

acollect module-attribute

acollect = alist

afilter module-attribute

afilter = awhere

amap module-attribute

amap = aselect

Functions

_atraverse_impl async

_atraverse_impl(value)

abatched async

abatched(iterator, size)

Yield fixed-size batches from iterator.

achain async

achain(iterator)

Flatten iterables yielded by iterator.

achain_with async

achain_with(iterator, *others)

Chain iterator with additional iterables.

adedup async

adedup(iterator, key=lambda x: x)

Yield unique items from iterator by tracking key values.

aenumerate async

aenumerate(iterator, start=0)

Enumerate items from iterator starting at start.

agroupby async

agroupby(iterator, keyfunc)

Group items by keyfunc returning a list of (key, values).

aislice async

aislice(iterator, *args)

Return a slice of items as a list using start/stop/step semantics.

aiter

aiter(iterator)

Normalize async iterables, iterators, or awaitables into an async iterator.

aizip async

aizip(iterator, *others)

Zip iterator with additional iterables, producing tuples.

alist async

alist(iterator)

Collect all items from iterator into a list.

Parameters:

Name Type Description Default
iterator AsyncIterator[T]

Source async iterator to exhaust.

required

Returns:

Type Description
list[T]

List containing every item produced by iterator.

anetcat async

anetcat(iterator, host, port)

Async TCP client sending bytes and yielding responses.

apermutations async

apermutations(iterator, r=None)

Yield permutations of items from iterator.

areverse async

areverse(iterator)

Yield items from iterator in reverse order.

aselect async

aselect(iterator, mapper)

Apply mapper to each item in an async iterator.

Parameters:

Name Type Description Default
iterator AsyncIterator[T]

Source async iterator to transform.

required
mapper AsyncMapper

Callable used to transform each element. May return awaitable results.

required

Returns:

Type Description
AsyncIterator[U]

Async iterator yielding the transformed values.

askip async

askip(iterator, count)

Skip count items from iterator before yielding the rest.

askip_while async

askip_while(iterator, predicate)

Skip items while predicate stays true, then yield the remainder.

asort async

asort(iterator, key=None, reverse=False)

Return a sorted list of the items from iterator.

async_iter_operator

async_iter_operator(func)

at async

at(iterator, value)

Append value to the items from iterator and return a list.

atail async

atail(iterator, count)

Collect the last count items into a deque.

atake async

atake(iterator, count)

Yield at most count items from iterator.

atake_while async

atake_while(iterator, predicate)

Yield items while predicate remains true.

atee async

atee(iterator)

Print each item before yielding it.

atranspose async

atranspose(iterator)

Transpose rows and columns of the provided iterables.

atraverse async

atraverse(iterator)

Traverse nested iterables and yield leaf values.

auniq async

auniq(iterator, key=lambda x: x)

Yield items from iterator removing consecutive duplicates.

awhere async

awhere(iterator, predicate)

Yield items from an async iterator for which predicate returns True.

Parameters:

Name Type Description Default
iterator AsyncIterator[T]

Source async iterator to filter.

required
predicate AsyncPredicate

Callable returning True for values that should pass through. May return awaitable results.

required

Returns:

Type Description
AsyncIterator[T]

Async iterator yielding values that satisfy the predicate.

ensure_async_callable

ensure_async_callable(func)

to_async_iterator async

to_async_iterator(stream)