asyncutils.iters¶
more_itertools.Functions¶
|
Async version of |
|
Async version of |
|
Whether all items in the (async) iterable are equal to each other according to the |
|
Async version of |
|
Append |
|
Return the index of the first occurrence of the maximum element in the (async) iterable |
|
Return the index of the first occurrence of the minimum element in the (async) iterable |
|
Convert a function that returns an awaitable resolving to an async iterable into one returning an async generator. |
|
|
|
Breadth-first search on a start node |
|
Brent's algorithm for cycle detection, assuming that a cycle is indeed present, given a function |
|
Async version of |
|
Return a canonicalized ordering of the items in |
|
An async generator that yields the sent value, starting with |
|
Flatten the (async) iterable |
|
Async version of |
Async version of |
|
|
Async version of |
|
Advance the (async) iterable |
|
Polynomial multiplication with coefficients from the two iterables. The first iterable is advanced on demand, meaning it may be infinite, but the second iterable is exhausted immediately, storing all its items in memory. |
|
Async version of |
|
Count down from |
|
Async version of |
|
Successive derangements of the elements in |
|
Depth-first search on a start node |
|
The discrete Fourier transform. O(n^2), since this library does not specialize in these operations. |
Successive distinct permutations of the elements in |
|
|
Like |
|
|
|
Yield every |
|
Yield every other item from an (async) iterable, optionally skipping the first item. |
|
Generate the prime factors of |
|
Async version of |
|
Async version of |
|
Return the first item in the (async) iterable |
|
Return the first item in the (async) iterable |
|
Flatten one level of nesting using |
|
|
|
An async generator that yields |
|
The probabilistic Freivalds algorithm to determine if the matrix product of |
|
Wraps |
|
|
|
Yield the given value, then return. |
|
Async version of |
|
|
|
Optimal solution to the secretary problem, using |
|
Optimal solution to the secretary problem, using |
|
Return the Hamming distance between two (async) iterables, using |
|
The inverse discrete Fourier transform. O(n^2) just like |
|
Return the length of the (async) iterable |
|
Interleave items of the iterables evenly according to the lengths if passed, and determined by calling the |
|
Interleave items of the iterables randomly, skipping exhausted iterables. |
|
Yield the items from the iterables in a round-robin fashion until at least one is exhausted. |
|
Feed |
|
Yield |
|
Whether the (async) iterable |
|
Async version of |
|
Probabilistically test for primality of |
|
Yield the indices at which |
|
Yield |
|
Yield the awaited output of |
|
Return the last item in the (async) iterable |
|
Yield |
|
Async version of |
|
Essentially the restriction of |
|
Matrix multiplication of |
|
Return the product of the matrices in the (async) iterable, preceded by |
|
Async version of |
Async version of |
|
|
Async version of |
|
|
Composition of |
|
|
Composition of |
Composition of |
|
Composition of |
|
|
Yield the items in the (async) iterable |
|
Return the |
|
Return the |
|
Return the |
|
Yield the items in the (async) iterable |
|
Async version of |
|
Return a tuple |
|
Async version of |
|
Compute the coefficients of the derivative of a polynomial. Both input and output iterables are in order of descending powers. |
|
Evaluate a polynomial at |
|
Generate the coefficients of a polynomial given its roots in order of descending powers. |
|
Yield |
|
Optimized version of |
|
Yield all the subsets of the (async) iterable |
Yield all the subsets of the items in the (async) iterable of hashable objects after consuming it at once and removing duplicates, as |
|
|
Prepend |
|
Return the product of the items in the (async) iterable, preceded by |
|
Async version of |
|
Return the number of items in the (async) iterable for which the predicate is true. |
Draw |
|
|
Generate a random derangement of items in the (async) iterable |
|
Choose a random permutation of the elements in |
|
Draw |
|
Draw |
|
Async version of |
|
Async version of |
|
Call the async function |
|
Change the shape of a tensor according to |
|
Reverse an (async) iterable, calling its |
|
Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over |
|
Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over |
|
Inverse of the above. |
|
Compress an (async) iterable into an async generator of pairs with run-length encoding. Items in the result are in the form |
|
Yield the median of all the items seen from |
|
Repeatedly yield the mean of the items in the iterable so far, and advance the iterable. |
|
The A-Chao with Jumps reservoir sampling algorithm. Chooses |
|
Algorithm L. Chooses |
|
Return a list representing a random full-length permutation of the items in |
|
Feed |
|
Protect an (async) iterable from being consumed by many parties concurrently by applying an async lock. |
|
|
|
Implementation of the Sieve of Eratosthenes, yielding prime numbers strictly smaller than |
|
|
|
Async version of |
|
Split an async iterator at each item satisfying |
|
Return an async generator containing the first |
|
Return the sum of squares of items in an (async) iterable of numbers as a number of the same type. |
|
Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a truthy value when called on the tuple unpacked. |
|
Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a falsy value when called on the tuple unpacked. |
|
Async version of |
|
Like |
|
|
Yield tuples of the form |
|
|
Yield all the contiguous subsequences of the (async) iterable |
|
Return the sum of the items in the (async) iterable, preceded by |
|
Return the sum of products of items in two iterables of numbers as a number of the same type. Not as precise as |
|
|
|
Yield the last |
|
Async version of |
|
|
|
Take items from the iterable while the predicate called on the item does not hold. |
|
|
|
Compute the transpose of a matrix. |
|
Yield overlapping triples of items from an (async) iterable. |
|
Yield unique elements from |
|
Yield items from the (async) iterable |
|
Yield items from the (async) iterable |
|
Given multiple (async) iterables, yield every item that is only seen in exactly one of the iterables. |
|
|
|
Async version of |
|
Async version of |
|
Return a list of the first |
|
More flexible but slightly slower implementation of |
|
Batch an (async) iterable into an async generator of lists. If |
|
Apply |
|
|
|
Return an async generator that yields nothing. Due to async generator finalization issues, this is not a constant like |
|
Return a list of the results of calling each async function in the first argument (an (async) iterable of functions), with the provided arguments. |
|
Like |
|
Like |
|
Return a task that calls |
|
Apply a transformation on an (async) iterable on top of another. |
|
Multiplication of a matrix |
|
|
|
|
|
Collect all items of an async iterable into a list. Faster than |
|
Convert the output of |
|
Convert the output of |
|
Whether the vectors |
|
Window an async iterable into an async generator of tuples of the specified size and step. You can send in a tuple |
Module Contents¶
- asyncutils.iters.aaccumulate[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- func: collections.abc.Callable[[T, T], T] = ...,
- *,
- initial: T | None = ...,
Async version of
itertools.accumulatethat is not a class.
- async asyncutils.iters.aall(it: asyncutils._internal.types.SupportsIteration[object]) bool[source]¶
Async version of
all().
- async asyncutils.iters.aallequal[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], object] = ...,
- strict: bool = ...,
Whether all items in the (async) iterable are equal to each other according to the
keyfunction. Check for identity rather than equality ifstrictisTrue.
- async asyncutils.iters.aany(it: asyncutils._internal.types.SupportsIteration[object]) bool[source]¶
Async version of
any().
- asyncutils.iters.aappend[T](val: T, it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Append
valto the (async) iterableit.
- async asyncutils.iters.aargmax[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- default: int = ...,
- async asyncutils.iters.aargmax(it: asyncutils._internal.types.SupportsIteration[C], *, default: int = ...) int
Return the index of the first occurrence of the maximum element in the (async) iterable
itaccording tokey, ordefaultif empty.
- async asyncutils.iters.aargmin[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- default: int = ...,
- async asyncutils.iters.aargmin(it: asyncutils._internal.types.SupportsIteration[C], *, default: int = ...) int
Return the index of the first occurrence of the minimum element in the (async) iterable
itaccording tokey, ordefaultif empty.
- asyncutils.iters.aawgenf2agenf[T, **P](
- f: collections.abc.Callable[P, collections.abc.AsyncIterable[T]],
- /,
Convert a function that returns an awaitable resolving to an async iterable into one returning an async generator.
- asyncutils.iters.abefore_and_after[T](
- pred: collections.abc.Callable[[T], object],
- it: asyncutils._internal.types.SupportsIteration[T],
atakewhile(), but return all remaining items in the second async generator (after the first is consumed).
- asyncutils.iters.abfs[H: collections.abc.Hashable](
- start: H,
- neighbours: collections.abc.Callable[[H], asyncutils._internal.types.SupportsIteration[H]],
- *,
- include_start: bool = ...,
Breadth-first search on a start node
start, given a functionneighboursthat returns an (async) iterable of neighbours to be traversed in order. Ifinclude_startisTrue, the start node is yielded first.
- async asyncutils.iters.abrent[T](
- next_node: collections.abc.Callable[[T], asyncutils._internal.types.SupportsIteration[T]],
- start: T,
- /,
Brent’s algorithm for cycle detection, assuming that a cycle is indeed present, given a function
next_nodereturning the next node from the previous. Return a tuple(node, la, mu), wherenodeis the first node involved in a cycle.next_nodeshould be deterministic.
- asyncutils.iters.ac3merge[T]( ) collections.abc.AsyncGenerator[T][source]¶
Async version of
functools._c3_mergethat doesn’t assume the input is an synchronous iterable of mutable sequences of classes.
- asyncutils.iters.acanonical[T](it: asyncutils._internal.types.SupportsIteration[T]) list[T][source]¶
Return a canonicalized ordering of the items in
it, which may change across different Python invocations or sessions.
- asyncutils.iters.acat[T](first: T) collections.abc.AsyncGenerator[T, T][source]¶
- asyncutils.iters.acat(first: None = ...) collections.abc.AsyncGenerator[T | None, T | None]
An async generator that yields the sent value, starting with
first(defaultNone).
- asyncutils.iters.acollapse(
- it: asyncutils._internal.types.SupportsIteration[object],
- base_typ: tuple[type, Ellipsis] | type = ...,
- levels: int | None = ...,
Flatten the (async) iterable
itby at mostlevelslevels, without collapsing objects of types specified inbase_typ.
- asyncutils.iters.acombinations[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int,
Async version of
itertools.combinations()that is not a class.
- asyncutils.iters.acombinations_with_replacement[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int,
Async version of
itertools.combinations_with_replacement()that is not a class.
- asyncutils.iters.acompress[T](
- data: asyncutils._internal.types.SupportsIteration[T],
- selectors: asyncutils._internal.types.SupportsIteration[object],
Async version of
itertools.compressthat is not a class.
- async asyncutils.iters.aconsume[T](it: asyncutils._internal.types.SupportsIteration[T], n: int | None = ...) None[source]¶
Advance the (async) iterable
itbynsteps, using a function-scoped executor created on demand where appropriate. If you want the item at the final position, useanth()instead.
- asyncutils.iters.aconvolve[X: (int, float, complex)](
- signal: asyncutils._internal.types.SupportsIteration[X],
- kernel: asyncutils._internal.types.SupportsIteration[X],
Polynomial multiplication with coefficients from the two iterables. The first iterable is advanced on demand, meaning it may be infinite, but the second iterable is exhausted immediately, storing all its items in memory.
- asyncutils.iters.acount(start: int = ..., step: int = ...) collections.abc.AsyncGenerator[int][source]¶
- asyncutils.iters.acount(start: float, step: int = ...) collections.abc.AsyncGenerator[float]
- asyncutils.iters.acount(start: float, step: float) collections.abc.AsyncGenerator[float]
- asyncutils.iters.acount(*, step: float) collections.abc.AsyncGenerator[float]
Async version of
itertools.countthat is not a class.
- asyncutils.iters.acountdown(n: int, step: int = ..., *, include_zero: bool = ...) collections.abc.AsyncGenerator[int][source]¶
Count down from
nto zero, excluding zero if it is to appear andinclude_zeroisFalse(the default), by a step size ofstep.
- asyncutils.iters.acycle[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Async version of
itertools.cyclethat is not a class.
- asyncutils.iters.aderangements[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int | None = ...,
Successive derangements of the elements in
itof sizer, or all sizes if not passed. Derangements are permutations with no fixed points.
- asyncutils.iters.adfs[H: collections.abc.Hashable](
- start: H,
- neighbours: collections.abc.Callable[[H], asyncutils._internal.types.SupportsIteration[H]],
- *,
- include_start: bool = ...,
Depth-first search on a start node
start, given a functionneighboursthat returns an (async) iterable of neighbours to be traversed in order. Ifinclude_startisTrue, the start node is yielded first.
- asyncutils.iters.adft(xarr: asyncutils._internal.types.SupportsIteration[complex], /) collections.abc.AsyncGenerator[complex][source]¶
The discrete Fourier transform. O(n^2), since this library does not specialize in these operations.
- asyncutils.iters.adistinct_permutations[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int | None = ...,
Successive distinct permutations of the elements in
itof sizer, or all sizes if not passed.
- asyncutils.iters.adoublestarmap[T](
- f: collections.abc.Callable[Ellipsis, T],
- it: asyncutils._internal.types.SupportsIteration[collections.abc.Mapping[str, Any]],
- /,
Like
amap(), but the iterables should yield mappings that are unpacked as arguments to the function.
- asyncutils.iters.adropwhile[T](
- pred: collections.abc.Callable[[T], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- skip_first: bool = ...,
- Async version of
itertools.dropwhilethat is not a class.Ifskip_firstisTrue, drop also the first item that fails the predicate.
- asyncutils.iters.aevery[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int,
- *,
- skip_first: bool = ...,
Yield every
n-th item from an (async) iterable, optionally skipping the first item.
- asyncutils.iters.aeveryother[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- skip_first: bool = ...,
Yield every other item from an (async) iterable, optionally skipping the first item.
- asyncutils.iters.afactor(n: int) collections.abc.AsyncGenerator[int][source]¶
Generate the prime factors of
nasynchronously. Do not rely on the resultant order.
- asyncutils.iters.afilter[T](
- f: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
Async version of
filterthat is not a class.
- asyncutils.iters.afilterfalse[T](
- f: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
Async version of
itertools.filterfalsethat is not a class.
- async asyncutils.iters.afirst[T](it: asyncutils._internal.types.SupportsIteration[T], default: T = ...) T[source]¶
Return the first item in the (async) iterable
it, ordefaultif passed anditis empty.
- async asyncutils.iters.afirsttrue[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- default: T | None = ...,
- pred: collections.abc.Callable[[T], object] = ...,
Return the first item in the (async) iterable
it
- asyncutils.iters.aflatten[T]( ) collections.abc.AsyncGenerator[T][source]¶
Flatten one level of nesting using
achainand return an async iterator over it.
- asyncutils.iters.aflatten_tensor(
- tensor: asyncutils._internal.types.SupportsIteration[object],
- base_typ: tuple[type, Ellipsis] | type = ...,
acollapse(), but using a different, more memory-efficient strategy that does not support thelevelsparameter.
- asyncutils.iters.aforever() collections.abc.AsyncGenerator[None][source]¶
An async generator that yields
Noneforever. Equivalent toarepeat(None).
- async asyncutils.iters.afreivalds(
- A: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
- B: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
- C: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
- k: int = ...,
The probabilistic Freivalds algorithm to determine if the matrix product of
AandBequalsC. O(kn^2) time, with a false positive rate of at most 2^(-k) and no false negatives.
- async asyncutils.iters.agather[T](
- it_of_its: asyncutils._internal.types.SupportsIteration[collections.abc.Awaitable[T]],
- return_exceptions: bool = ...,
Wraps
asyncio.gather()to accept (async) iterables as the first argument, so that unpacking is not needed.
- asyncutils.iters.agetitems_from_indices[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- indices: asyncutils._internal.types.SupportsIteration[SupportsIndex],
- setatend: asyncio.Future[float] | None = ...,
- finish: bool = ...,
- Take an (async) iterable and an (async) iterable of integers interpreted as indices, and immediately returns a list of futures.Their eventual results represent the items of that iterable at the corresponding index.Also begin consumption of the iterable in the background.Exceptions will be set in the futures that are not done if results are encountered during iteration or if the index is out of bounds.Pass in a
Futurefor thesetatendparameter, which cancels the background consumption of the async iterable onceit is done and cancels the undone futures.Attention
Negative indices would consume the whole iterable at once if not already consumed.
Warning
Do not set the result of any returned future; instead, if the result is no longer relevant, cancel the future.
Note
The consumption stops as soon as all the required results are pushed into the respective futures.
- asyncutils.iters.agives[T](x: T) collections.abc.AsyncGenerator[T][source]¶
Yield the given value, then return.
- asyncutils.iters.agroupby[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], T] = ...,
- asyncutils.iters.agroupby(
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], R],
Async version of
itertools.groupbythat is not a class.
- asyncutils.iters.agrouper[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int,
- fillvalue: T | asyncutils._internal.types.RaiseType = ...,
- Collect items of the (async) iterable
itinto tuples of lengthneach.Otherwise, pad the last group withfillvalueto lengthnif needed. No padding is done if not passed.
- async asyncutils.iters.aguessmax[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- estlen: int,
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison] = ...,
- default: T = ...,
- finish_event: asyncutils._internal.types.EventProt | None = ...,
Optimal solution to the secretary problem, using
keyto guess the maximum item, which is the candidate chosen, with 36.8% accuracy by consuming 36.8% of the (async) iterable.
- async asyncutils.iters.aguessmin[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- estlen: int,
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison] = ...,
- default: T = ...,
- finish_event: asyncutils._internal.types.EventProt | None = ...,
Optimal solution to the secretary problem, using
keyto guess the minimum item, which is the candidate chosen, with 36.8% accuracy by consuming 36.8% of the (async) iterable.
- async asyncutils.iters.ahammingdist[T](
- a: asyncutils._internal.types.SupportsIteration[T],
- b: asyncutils._internal.types.SupportsIteration[T],
- /,
- cmpeq: collections.abc.Callable[[T, T], object] = ...,
Return the Hamming distance between two (async) iterables, using
cmpeqto check for equality if passed.
- asyncutils.iters.aidft(Xarr: asyncutils._internal.types.SupportsIteration[complex], /) collections.abc.AsyncGenerator[complex][source]¶
The inverse discrete Fourier transform. O(n^2) just like
adft().
- async asyncutils.iters.ailen(it: asyncutils._internal.types.SupportsIteration[object]) int[source]¶
Return the length of the (async) iterable
it, consuming it entirely.
- asyncutils.iters.ainterleave_evenly[T](
- its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
- lengths: asyncutils._internal.types.SupportsIteration[int] | None = ...,
Interleave items of the iterables evenly according to the lengths if passed, and determined by calling the
__len__()method on the iterables if present otherwise.
- asyncutils.iters.ainterleave_randomly[T]( ) collections.abc.AsyncGenerator[T][source]¶
Interleave items of the iterables randomly, skipping exhausted iterables.
- asyncutils.iters.ainterleave_stopearly[T](*it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Yield the items from the iterables in a round-robin fashion until at least one is exhausted.
- asyncutils.iters.aintersend[T, R](
- i1: collections.abc.AsyncGenerator[T, R],
- i2: collections.abc.AsyncGenerator[R, T],
Feed
i1andi2into each other and yield tuples of the form(yielded_from_i1, yielded_from_i2).
- asyncutils.iters.aintersperse[T](e: T, it: asyncutils._internal.types.SupportsIteration[T], n: int = ...) collections.abc.AsyncGenerator[T][source]¶
Yield
e, then the nextnitems init, and repeat untilitis exhausted.
- async asyncutils.iters.aisempty(it: asyncutils._internal.types.SupportsIteration[object]) bool[source]¶
Whether the (async) iterable
itis empty.
- asyncutils.iters.aislice[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- stop: SupportsIndex | None = ...,
- /,
- asyncutils.iters.aislice(
- it: asyncutils._internal.types.SupportsIteration[T],
- start: SupportsIndex | None,
- stop: SupportsIndex | None,
- step: SupportsIndex | None = ...,
- /,
Async version of
itertools.islicethat is not a class.
- async asyncutils.iters.aisprime(n: int) bool[source]¶
Probabilistically test for primality of
n. O(log^3 n), with false-positive rate below 2^(-128) for integers above 10^24.
- asyncutils.iters.aiter_idx[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- value: T,
- start: int = ...,
- stop: int | None = ...,
Yield the indices at which
valueoccurs initwithinstartandstop.
- asyncutils.iters.aiterate[T](f: collections.abc.Callable[[T], collections.abc.Awaitable[T]], start: T) collections.abc.AsyncGenerator[T][source]¶
Yield
start, then the awaited output offcalled on the previous output repeatedly.
- asyncutils.iters.aiterexcept[T](
- f: collections.abc.Callable[[], collections.abc.Awaitable[T]],
- exc: asyncutils._internal.types.Exceptable,
- first: collections.abc.Callable[[], collections.abc.Awaitable[T]] = ...,
Yield the awaited output of
first, thenfcalled with no arguments repeatedly until an exception present inexcoccurs.
- async asyncutils.iters.alast[T](it: asyncutils._internal.types.SupportsIteration[T], default: T = ...) T[source]¶
Return the last item in the (async) iterable
it, ordefaultif passed anditis empty.
- asyncutils.iters.aloops(n: int) collections.abc.AsyncGenerator[None][source]¶
Yield
Nonentimes. Equivalent tobase.take(aforever(), n)andarepeat(None, n), but without creating intermediate integers.
- asyncutils.iters.amap[T, R](
- f: collections.abc.Callable[[T], collections.abc.Awaitable[R]],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- await_: Literal[True],
- strict: Literal[False] = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T], R],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- await_: Literal[False] = ...,
- strict: Literal[False] = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T, S], collections.abc.Awaitable[R]],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- await_: Literal[True],
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T, S], R],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- await_: Literal[False] = ...,
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T, S, V], collections.abc.Awaitable[R]],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[S],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- await_: Literal[True],
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T, S, V], R],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[S],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- await_: Literal[False] = ...,
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T, S, V, U], collections.abc.Awaitable[R]],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[S],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- await_: Literal[True],
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[T, S, V, U], R],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[S],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- await_: Literal[False] = ...,
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[*tuple[T, ...]], collections.abc.Awaitable[R]],
- /,
- *its: asyncutils._internal.types.SupportsIteration[T],
- await_: Literal[True],
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[[*tuple[T, ...]], R],
- /,
- *its: asyncutils._internal.types.SupportsIteration[T],
- await_: Literal[False] = ...,
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[Ellipsis, collections.abc.Awaitable[R]],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- await_: Literal[True],
- strict: bool = ...,
- asyncutils.iters.amap(
- f: collections.abc.Callable[Ellipsis, R],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- await_: Literal[False] = ...,
- strict: bool = ...,
Async version of
mapthat is not a class, withawait_dictating whether the return value of the function is to be awaited before yielding.
- asyncutils.iters.amapif[T, R](
- f: collections.abc.Callable[[T], R],
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- await_: Literal[False] = ...,
- asyncutils.iters.amapif(
- f: collections.abc.Callable[[T], collections.abc.Awaitable[R]],
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- await_: Literal[True],
Essentially the restriction of
amultimapif()to one (async) iterable, which allows for more flexibility.
- asyncutils.iters.amatmul[X: (int, float, complex)](
- M: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[X]],
- N: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[X]],
Matrix multiplication of
MandN. O(n^3) time, since this library does not specialize in these operations.
- async asyncutils.iters.amatprod[M: asyncutils._internal.types.SupportsMatMul](it: asyncutils._internal.types.SupportsIteration[M], start: M) M[source]¶
Return the product of the matrices in the (async) iterable, preceded by
startif passed.
- async asyncutils.iters.amax[C: asyncutils._internal.types.SupportsRichComparison](it: asyncutils._internal.types.SupportsIteration[C], *, default: C = ...) C[source]¶
- async asyncutils.iters.amax(arg1: C, arg2: C, /, *args: C, default: C = ...) C
- async asyncutils.iters.amax(
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- default: T = ...,
- async asyncutils.iters.amax(
- arg1: T,
- arg2: T,
- /,
- *args: T,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- default: T = ...,
Async version of
max().
- asyncutils.iters.amergesortedby[C: asyncutils._internal.types.SupportsRichComparison](
- its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[C]],
- *,
- key: collections.abc.Callable[[C], C] = ...,
- await_: Literal[False] = ...,
- reverse: bool = ...,
- asyncutils.iters.amergesortedby(
- its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- await_: Literal[False] = ...,
- reverse: bool = ...,
- asyncutils.iters.amergesortedby(
- its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
- *,
- key: collections.abc.Callable[[T], collections.abc.Awaitable[asyncutils._internal.types.SupportsRichComparison]],
- await_: Literal[True],
- reverse: bool = ...,
Async version of
heapq.merge().
- async asyncutils.iters.amin[C: asyncutils._internal.types.SupportsRichComparison](it: asyncutils._internal.types.SupportsIteration[C], *, default: C = ...) C[source]¶
- async asyncutils.iters.amin(arg1: C, arg2: C, /, *args: C, default: C = ...) C
- async asyncutils.iters.amin(
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- default: T = ...,
- async asyncutils.iters.amin(
- arg1: T,
- arg2: T,
- /,
- *args: T,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- default: T = ...,
Async version of
min().
- asyncutils.iters.amultifilter[T](
- pred: collections.abc.Callable[[tuple[T]], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilter(
- pred: collections.abc.Callable[[tuple[T, R]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilter(
- pred: collections.abc.Callable[[tuple[T, R, V]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilter(
- pred: collections.abc.Callable[[tuple[T, R, V, U]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilter(
- pred: collections.abc.Callable[[tuple[T, R, V, U, S]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilter(
- pred: collections.abc.Callable[[tuple[T, Ellipsis]], object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[T],
- strict: bool = ...,
- asyncutils.iters.amultifilter(
- pred: collections.abc.Callable[[tuple[Any, Ellipsis]], object],
- i1: asyncutils._internal.types.SupportsIteration[object],
- i2: asyncutils._internal.types.SupportsIteration[object],
- i3: asyncutils._internal.types.SupportsIteration[object],
- i4: asyncutils._internal.types.SupportsIteration[object],
- i5: asyncutils._internal.types.SupportsIteration[object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse[T](
- pred: collections.abc.Callable[[tuple[T]], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse(
- pred: collections.abc.Callable[[tuple[T, R]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse(
- pred: collections.abc.Callable[[tuple[T, R, V]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse(
- pred: collections.abc.Callable[[tuple[T, R, V, U]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse(
- pred: collections.abc.Callable[[tuple[T, R, V, U, S]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse(
- pred: collections.abc.Callable[[tuple[T, Ellipsis]], object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[T],
- strict: bool = ...,
- asyncutils.iters.amultifilterfalse(
- pred: collections.abc.Callable[[tuple[Any, Ellipsis]], object],
- i1: asyncutils._internal.types.SupportsIteration[object],
- i2: asyncutils._internal.types.SupportsIteration[object],
- i3: asyncutils._internal.types.SupportsIteration[object],
- i4: asyncutils._internal.types.SupportsIteration[object],
- i5: asyncutils._internal.types.SupportsIteration[object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- strict: bool = ...,
Composition of
afilterfalse()andazip().
- asyncutils.iters.amultimapif[T, R](
- f: collections.abc.Callable[[T], R],
- pred: collections.abc.Callable[[tuple[T]], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- await_: Literal[False] = ...,
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T], collections.abc.Awaitable[R]],
- pred: collections.abc.Callable[[tuple[T]], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- await_: Literal[True],
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T, V], R],
- pred: collections.abc.Callable[[tuple[T, V]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- await_: Literal[False] = ...,
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T, V], collections.abc.Awaitable[R]],
- pred: collections.abc.Callable[[tuple[T, V]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- await_: Literal[True],
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T, V, S], R],
- pred: collections.abc.Callable[[tuple[T, V, S]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[V],
- i3: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- await_: Literal[False] = ...,
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T, V, S], collections.abc.Awaitable[R]],
- pred: collections.abc.Callable[[tuple[T, V, S]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[V],
- i3: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- await_: Literal[True],
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T, V, S, U], R],
- pred: collections.abc.Callable[[tuple[T, V, S, U]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[V],
- i3: asyncutils._internal.types.SupportsIteration[S],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- await_: Literal[False] = ...,
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[T, V, S, U], collections.abc.Awaitable[R]],
- pred: collections.abc.Callable[[tuple[T, V, S, U]], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[V],
- i3: asyncutils._internal.types.SupportsIteration[S],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- await_: Literal[True],
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[*Ts], R],
- pred: collections.abc.Callable[[tuple[*Ts]], object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- await_: Literal[False] = ...,
- asyncutils.iters.amultimapif(
- f: collections.abc.Callable[[*Ts], collections.abc.Awaitable[R]],
- pred: collections.abc.Callable[[tuple[*Ts]], object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- await_: Literal[True],
Composition of
astarmap(),afilter()andazip().
- asyncutils.iters.amultistarfilter[T](
- pred: collections.abc.Callable[[T], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilter(
- pred: collections.abc.Callable[[T, R], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilter(
- pred: collections.abc.Callable[[T, R, V], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilter(
- pred: collections.abc.Callable[[T, R, V, U], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilter(
- pred: collections.abc.Callable[[T, R, V, U, S], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilter(
- pred: collections.abc.Callable[[*tuple[T, ...]], object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[T],
- strict: bool = ...,
- asyncutils.iters.amultistarfilter(
- pred: collections.abc.Callable[[*tuple[Any, ...]], object],
- i1: asyncutils._internal.types.SupportsIteration[object],
- i2: asyncutils._internal.types.SupportsIteration[object],
- i3: asyncutils._internal.types.SupportsIteration[object],
- i4: asyncutils._internal.types.SupportsIteration[object],
- i5: asyncutils._internal.types.SupportsIteration[object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- strict: bool = ...,
Composition of
astarfilter()andazip().
- asyncutils.iters.amultistarfilterfalse[T](
- pred: collections.abc.Callable[[T], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilterfalse(
- pred: collections.abc.Callable[[T, R], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilterfalse(
- pred: collections.abc.Callable[[T, R, V], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilterfalse(
- pred: collections.abc.Callable[[T, R, V, U], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilterfalse(
- pred: collections.abc.Callable[[T, R, V, U, S], object],
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- strict: bool = ...,
- asyncutils.iters.amultistarfilterfalse(
- pred: collections.abc.Callable[[*tuple[T, ...]], object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[T],
- strict: bool = ...,
- asyncutils.iters.amultistarfilterfalse(
- pred: collections.abc.Callable[[*tuple[Any, ...]], object],
- i1: asyncutils._internal.types.SupportsIteration[object],
- i2: asyncutils._internal.types.SupportsIteration[object],
- i3: asyncutils._internal.types.SupportsIteration[object],
- i4: asyncutils._internal.types.SupportsIteration[object],
- i5: asyncutils._internal.types.SupportsIteration[object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- strict: bool = ...,
Composition of
astarfilterfalse()andazip().
- asyncutils.iters.ancycles[T](it: asyncutils._internal.types.SupportsIteration[T], n: int) collections.abc.AsyncGenerator[T][source]¶
Yield the items in the (async) iterable
itover and over for a total ofncycles.
- async asyncutils.iters.anth[T](it: asyncutils._internal.types.SupportsIteration[T], n: int, default: T = ...) T[source]¶
Return the
n-th item of the (async) iterableit, ordefaultif passed and there is no such item.
- async asyncutils.iters.anth_or_last[T](it: asyncutils._internal.types.SupportsIteration[T], n: int, default: T = ...) T[source]¶
Return the
n-th item in the (async) iterableit, or the last item if out of bounds, ordefaultif passed anditis empty.
- asyncutils.iters.anthcombination[T](it: asyncutils._internal.types.SupportsIteration[T], r: int, idx: int) collections.abc.AsyncGenerator[T][source]¶
Return the
idx-th combination ofrelements from the input iterableit, in lexicographic order.
- asyncutils.iters.aonline_sorter[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- reverse: bool = ...,
- slow: bool = ...,
- asyncutils.iters.aonline_sorter(
- it: asyncutils._internal.types.SupportsIteration[C],
- *,
- reverse: bool = ...,
- slow: bool = ...,
- Sort items from an (async) iterable and those sent in on the fly in the async generator interface (i.e. by awaitingthe return value of
asend()), according tokeyandreverse.Does not work well with items that areNone.Evaluates the truthiness of theslowparameter every time a new item is received, and if it isTrue, offloads the evaluation of thekeyfor that item to an executor, such that the__bool__()method onslowmay reflect the state of the program but can also bea plain boolean.Note
Uses a stable variant of heap sort internally, which is O(n log n) time and O(n) space.
Changed in version 0.9.9: The
itparameter is now required because an async generator can only be primed asynchronously, and a non-Nonevalue cannot be sent in to start the async generator, causing the resultant generator to always be empty. Ifititself is empty, the generator will also be empty.
- asyncutils.iters.apadnone[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T | None][source]¶
Yield the items in the (async) iterable
it, followed byNoneindefinitely.
- asyncutils.iters.apairwise[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, T]][source]¶
Async version of
itertools.pairwise()that is not a class.
- asyncutils.iters.apartition[T](
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
Return a tuple
(fgen, tgen).tgenis an async generator yielding the items initpassing the predicate, andfgenthe others.
- asyncutils.iters.apermutations[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int | None = ...,
Async version of
itertools.permutations()that is not a class.
- asyncutils.iters.apolynomial_derivative[X: (int, float, complex)](coeff: asyncutils._internal.types.SupportsIteration[X]) collections.abc.AsyncGenerator[X][source]¶
Compute the coefficients of the derivative of a polynomial. Both input and output iterables are in order of descending powers.
- async asyncutils.iters.apolynomial_eval[X: (int, float, complex)](coeff: asyncutils._internal.types.SupportsIteration[X], x: X) X[source]¶
Evaluate a polynomial at
xgiven its coefficients in order of descending powers.
- asyncutils.iters.apolynomial_from_roots[X: (int, float, complex)](roots: asyncutils._internal.types.SupportsIteration[X]) collections.abc.AsyncGenerator[X][source]¶
Generate the coefficients of a polynomial given its roots in order of descending powers.
- asyncutils.iters.apowers[X: (int, float, complex)](base: X, start: X = ...) collections.abc.AsyncGenerator[X][source]¶
Yield
start,start*base,start*base*base, …Changed in version 0.9.9: When it is found that the base is a perfect power of two, this will delegate to
apowers_of_two()as an optimization.
- asyncutils.iters.apowers_of_two(*, init: int = ..., init_shift: int = ..., shift: int = ...) collections.abc.AsyncGenerator[int][source]¶
Optimized version of
apowers()using bit shift operations for powers of two, four, eight, etc. Yieldinit<<init_shift,init<<init_shift+shift,init<<init_shift+2*shift, …
- asyncutils.iters.apowerset[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]¶
Yield all the subsets of the (async) iterable
it(by index!) as tuples, starting with the empty tuple.
- asyncutils.iters.apowersetofsets[H: collections.abc.Hashable](
- it: asyncutils._internal.types.SupportsIteration[H],
- *,
- frozen: Literal[True] = ...,
- asyncutils.iters.apowersetofsets(
- it: asyncutils._internal.types.SupportsIteration[H],
- *,
- frozen: Literal[False],
Yield all the subsets of the items in the (async) iterable of hashable objects after consuming it at once and removing duplicates, as
frozenset’s iffrozenisTrue(the default) andset’s otherwise.
- asyncutils.iters.aprepend[T](val: T, it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Prepend
valto the (async) iterableit.
- async asyncutils.iters.aprod[X: (int, float, complex)](it: asyncutils._internal.types.SupportsIteration[X], start: X = ...) X[source]¶
Return the product of the items in the (async) iterable, preceded by
startif passed.
- asyncutils.iters.aproduct[T](
- i1: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- repeat: Literal[1] = ...,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- repeat: int,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- repeat: Literal[1] = ...,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- repeat: int,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- repeat: Literal[1] = ...,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- repeat: int,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- repeat: Literal[1] = ...,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- repeat: int,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- repeat: Literal[1] = ...,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- repeat: int,
- asyncutils.iters.aproduct(
- i1: asyncutils._internal.types.SupportsIteration[object],
- i2: asyncutils._internal.types.SupportsIteration[object],
- i3: asyncutils._internal.types.SupportsIteration[object],
- i4: asyncutils._internal.types.SupportsIteration[object],
- i5: asyncutils._internal.types.SupportsIteration[object],
- /,
- *its: asyncutils._internal.types.SupportsIteration[object],
- repeat: int = ...,
- asyncutils.iters.aproduct(
- *its: asyncutils._internal.types.SupportsIteration[T],
- repeat: int = ...,
Async version of
itertools.productthat is not a class.
- async asyncutils.iters.aquantify[T](it: asyncutils._internal.types.SupportsIteration[T], pred: collections.abc.Callable[[T], object] = ...) int[source]¶
Return the number of items in the (async) iterable for which the predicate is true.
- asyncutils.iters.arandom_combination_with_replacement[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int,
Draw
ritems at random from the input iterableit, with replacement.
- async asyncutils.iters.arandom_derangement[T](it: asyncutils._internal.types.SupportsIteration[T]) tuple[T, Ellipsis][source]¶
Generate a random derangement of items in the (async) iterable
it.
- asyncutils.iters.arandom_permutation[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- r: int | None = ...,
Choose a random permutation of the elements in
itof sizer, or all sizes if not passed.
- asyncutils.iters.arandomcombination[T](it: asyncutils._internal.types.SupportsIteration[T], r: int) collections.abc.AsyncGenerator[T][source]¶
Draw
ritems at random from the input iterableit, without replacement.
- asyncutils.iters.arandomproduct[T](*its: asyncutils._internal.types.SupportsIteration[T], n: int = ...) collections.abc.AsyncGenerator[T][source]¶
Draw
nitems from each of the input iterablesitsat random.
- asyncutils.iters.arange(stop: int, /) collections.abc.AsyncGenerator[int][source]¶
- asyncutils.iters.arange(start: int, stop: int, /) collections.abc.AsyncGenerator[int]
- asyncutils.iters.arange(start: int, stop: int, step: int, /) collections.abc.AsyncGenerator[int]
Async version of
rangethat is not a class.
- asyncutils.iters.arepeat[T](elem: T, n: int = ...) collections.abc.AsyncGenerator[T][source]¶
Async version of
itertools.repeatthat is not a class.
- asyncutils.iters.arepeatfunc[T, *Ts](
- f: collections.abc.Callable[[*Ts], collections.abc.Awaitable[T]],
- times: int | None = ...,
- *a: *Ts,
Call the async function
fwith argumentsarepeatedly fortimestimes, or indefinitely iftimesis not passed, and yield the results awaited.
- asyncutils.iters.areshape[T](
- mat: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
- shape: int,
- asyncutils.iters.areshape(
- mat: asyncutils._internal.types.SupportsIteration[object],
- shape: asyncutils._internal.types.SupportsIteration[int],
Change the shape of a tensor according to
shape. For an integershape, the matrix must be 2D andshapeis the number of output columns.
- asyncutils.iters.areversed[T]( ) collections.abc.AsyncGenerator[T][source]¶
Reverse an (async) iterable, calling its
__reversed__()method if present, falling back to consuming all the items and yielding them in reverse order.
- asyncutils.iters.aroundrobin[T](*its: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over
aroundrobin2()for less iterables.
- asyncutils.iters.aroundrobin2[T](*its: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over
aroundrobin()for more iterables.
- asyncutils.iters.arunlength_decode[T](it: asyncutils._internal.types.SupportsIteration[tuple[T, int]], /) collections.abc.AsyncGenerator[T][source]¶
Inverse of the above.
- asyncutils.iters.arunlength_encode[T](it: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[tuple[T, int]][source]¶
Compress an (async) iterable into an async generator of pairs with run-length encoding. Items in the result are in the form
(item, count), whereitemis an item from the input iterable andcountis the number of times it is repeated consecutively.
- asyncutils.iters.arunning_median[N: (int, float)](
- it: asyncutils._internal.types.SupportsIteration[N],
- *,
- maxlen: SupportsIndex | None = ...,
Yield the median of all the items seen from
itwithin a window of sizemaxlen, then advance it.
- asyncutils.iters.arunningmean[X: (int | float, complex)](it: asyncutils._internal.types.SupportsIteration[X]) collections.abc.AsyncGenerator[X][source]¶
Repeatedly yield the mean of the items in the iterable so far, and advance the iterable.
- async asyncutils.iters.asample_weighted[T](
- it: asyncutils._internal.types.SupportsIteration[tuple[T, float]],
- k: int,
- *,
- rrange: collections.abc.Callable[[int], int] = ...,
- rand: collections.abc.Callable[[], float] = ...,
The A-Chao with Jumps reservoir sampling algorithm. Chooses
kitems from an (async) iterable of(item, weight)pairs, where the probability of each item being chosen is proportional to its weight.rrangeandrandshould be therandrange()andrandom()methods of a random device respectively.
- async asyncutils.iters.asamplel[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- k: int,
- *,
- rrange: collections.abc.Callable[[int], int] = ...,
- rand: collections.abc.Callable[[], float] = ...,
Algorithm L. Chooses
kitems from an (async) iterable of items, where each item is chosen with equal probability.rrangeandrandshould be therandrange()andrandom()methods of a random device respectively.
- async asyncutils.iters.asattolo[T](it: asyncutils._internal.types.SupportsIteration[T], /) list[T][source]¶
Return a list representing a random full-length permutation of the items in
it.
- asyncutils.iters.asendstream[T, R](
- i1: collections.abc.AsyncGenerator[T, R],
- i2: asyncutils._internal.types.SupportsIteration[R],
Feed
i2intoi1and yield the results.
- asyncutils.iters.aserialize[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]¶
Protect an (async) iterable from being consumed by many parties concurrently by applying an async lock.
- asyncutils.iters.aside_effect[T](
- f: collections.abc.Callable[[list[T]], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- size: int,
- before: collections.abc.Callable[[], object] | None = ...,
- after: collections.abc.Callable[[], object] | None = ...,
- asyncutils.iters.aside_effect(
- f: collections.abc.Callable[[T], object],
- it: asyncutils._internal.types.SupportsIteration[T],
- /,
- *,
- size: None = ...,
- before: collections.abc.Callable[[], object] | None = ...,
- after: collections.abc.Callable[[], object] | None = ...,
- Apply a side effect function
fto each item in an (async) iterableitand yield the items unchanged in an async generator.Ifsizeis specified, the side effect function is applied to batches of that size instead of individual items, but the items arestill yielded separately.Thebeforeandafterfunctions are called before and after the iteration, respectively, butafteris not called ifbeforefails.
- asyncutils.iters.asieve(n: int) collections.abc.AsyncGenerator[int][source]¶
Implementation of the Sieve of Eratosthenes, yielding prime numbers strictly smaller than
nin order in an async generator.
- asyncutils.iters.asliced[T: asyncutils._internal.types.SupportsSlicing[Any]](seq: T, n: int, strict: bool = ...) collections.abc.AsyncGenerator[T][source]¶
- Slice a slicable object
seq(so named because these are usually sequences) and yield slices of the sizen, which should be of the same type asseq, from the start to the end.IfstrictisTrue, raiseValueErrorif the length of any slice is less thann(should only happen for the last slice unless the__getitem__()method is misimplemented).
- asyncutils.iters.asorted[C: asyncutils._internal.types.SupportsRichComparison](it: asyncutils._internal.types.SupportsIteration[C], *, reverse: bool = ...) list[C][source]¶
- asyncutils.iters.asorted(
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
- reverse: bool = ...,
Async version of
sorted(). O(n log n) time and O(n) space, but nowhere near as optimized as the builtin version.
- asyncutils.iters.asplitat[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- pred: collections.abc.Callable[[T], object],
- maxsplit: int = ...,
- keep_sep: bool = ...,
Split an async iterator at each item satisfying
pred, withkeep_sepdictating whether the separator is to be included as the last item of each list.
- asyncutils.iters.aspy[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int = ...,
Return an async generator containing the first
nitems, and another containing all the original items.
- async asyncutils.iters.asquaresum[X: (int, float, complex)](it: asyncutils._internal.types.SupportsIteration[X]) X[source]¶
Return the sum of squares of items in an (async) iterable of numbers as a number of the same type.
- asyncutils.iters.astarfilter[T](
- pred: collections.abc.Callable[[*tuple[T, ...]], object],
- it: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a truthy value when called on the tuple unpacked.
- asyncutils.iters.astarfilterfalse[T](
- pred: collections.abc.Callable[[*tuple[T, ...]], object],
- it: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a falsy value when called on the tuple unpacked.
- asyncutils.iters.astarmap[*Ts, R](
- f: collections.abc.Callable[[*Ts], R],
- it: asyncutils._internal.types.SupportsIteration[tuple[*Ts]],
- /,
- await_: Literal[False] = ...,
- asyncutils.iters.astarmap(
- f: collections.abc.Callable[[*Ts], collections.abc.Awaitable[R]],
- it: asyncutils._internal.types.SupportsIteration[tuple[*Ts]],
- /,
- await_: Literal[True],
Async version of
itertools.starmapthat is not a class.await_specifies whether to await the return value of the transformation function.
- asyncutils.iters.astarmap_with_kwds[T](
- f: collections.abc.Callable[Ellipsis, T],
- it: asyncutils._internal.types.SupportsIteration[tuple[collections.abc.Iterable[Any], collections.abc.Mapping[str, Any]]],
- /,
Like
amap(), but the iterable should yield tuples of the form(args, kwargs), whereargsis an iterable of positional arguments andkwargsis a mapping of keyword arguments.
- asyncutils.iters.asubslices[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]¶
asubstrings(), but yield all subslices containing the first item first in ascending order of length, then all subslices containing the second item but not the first, and so on.
- asyncutils.iters.asubstr_indices[S: (str, bytes, bytearray)](seq: S, reverse: bool = ...) collections.abc.AsyncGenerator[tuple[S, int, int]][source]¶
- asyncutils.iters.asubstr_indices(
- seq: asyncutils._internal.types.SupportsSlicing[T],
- reverse: bool = ...,
Yield tuples of the form
(substr, start, end), wheresubstris a contiguous subsequence ofseqstarting at indexstartand ending at indexend-1(such that its length isend-start).
- asyncutils.iters.asubstrings[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]¶
Yield all the contiguous subsequences of the (async) iterable
itas tuples, in increasing order of length.
- async asyncutils.iters.asum[X: (int, float, complex)](it: asyncutils._internal.types.SupportsIteration[X], start: X = ...) X[source]¶
Return the sum of the items in the (async) iterable, preceded by
startif passed.
- async asyncutils.iters.asumprod[X: (int, float, complex)](p: asyncutils._internal.types.SupportsIteration[X], q: asyncutils._internal.types.SupportsIteration[X], /) X[source]¶
Return the sum of products of items in two iterables of numbers as a number of the same type. Not as precise as
math.fsumprod()for floating-point numbers, but supports async iterables.
- asyncutils.iters.atabulate[T](
- f: collections.abc.Callable[[int], T],
- start: int = ...,
- step: int = ...,
- /,
- *,
- await_: Literal[False] = ...,
- asyncutils.iters.atabulate(
- f: collections.abc.Callable[[int], collections.abc.Awaitable[T]],
- start: int = ...,
- step: int = ...,
- /,
- *,
- await_: Literal[True],
- asyncutils.iters.atail[T](n: int, it: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[T][source]¶
Yield the last
nitems from the (async) iterableit.
- asyncutils.iters.atakewhile[T](
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
Async version of
itertools.takewhilethat is not a class.
- asyncutils.iters.atakewhile_inclusive[T](
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
atakewhile(), but yielding the first falsy item last.
- asyncutils.iters.atakewhilenot[T](
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
Take items from the iterable while the predicate called on the item does not hold.
- asyncutils.iters.atakewhilenot_inclusive[T](
- pred: collections.abc.Callable[[T], object] | None,
- it: asyncutils._internal.types.SupportsIteration[T],
atakewhilenot(), but yielding the first truthy item last.
- asyncutils.iters.atranspose[T]( ) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]¶
Compute the transpose of a matrix.
- asyncutils.iters.atriplewise[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, T, T]][source]¶
Yield overlapping triples of items from an (async) iterable.
- asyncutils.iters.aunique[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison] | None = ...,
- reverse: bool = ...,
Yield unique elements from
itin sorted order, according tokey, which should not be too expensive. IfreverseisTrue, yield in descending order.
- asyncutils.iters.aunique_everseen[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], object] = ...,
Yield items from the (async) iterable
it, without yielding items already previously yielded.
- asyncutils.iters.aunique_justseen[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- key: collections.abc.Callable[[T], object] = ...,
Yield items from the (async) iterable
it, without yielding consecutive duplicate items.
- asyncutils.iters.aunique_to_each[H: collections.abc.Hashable](*its: asyncutils._internal.types.SupportsIteration[H]) collections.abc.AsyncGenerator[H][source]¶
Given multiple (async) iterables, yield every item that is only seen in exactly one of the iterables.
- async asyncutils.iters.aunzip[T](
- ait: asyncutils._internal.types.SupportsIteration[tuple[T]],
- *,
- put_batch: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T | R]],
- *,
- put_batch: int = ...,
- fillvalue: R,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T, S]],
- *,
- put_batch: int = ...,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, S | R]],
- *,
- put_batch: int = ...,
- fillvalue: R,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T, S, V]],
- *,
- put_batch: int = ...,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, S | R, V | R]],
- *,
- put_batch: int = ...,
- fillvalue: R,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T, S, V, U]],
- *,
- put_batch: int = ...,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, S | R, V | R, U | R]],
- *,
- put_batch: int = ...,
- fillvalue: R,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T, Ellipsis]],
- *,
- put_batch: int = ...,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, Ellipsis]],
- *,
- put_batch: int = ...,
- fillvalue: R,
- maxqsize: int = ...,
- async asyncutils.iters.aunzip(
- ait: asyncutils._internal.types.SupportsIteration[tuple[Any, Ellipsis]],
- *,
- put_batch: int = ...,
- fillvalue: object = ...,
- maxqsize: int = ...,
- This function operates lazily, consuming items from the async iterable only when needed, in batches of size
put_batch(defaultcontext.AUNZIP_DEFAULT_PUT_BATCH) and caching other items in queues of capacitymaxqsize(defaultcontext.AUNZIP_DEFAULT_MAX_QSIZE).Warning
This function may require significant auxiliary space.
- asyncutils.iters.azip[T](i1: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[tuple[T]][source]¶
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- strict: Literal[True],
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- strict: Literal[True],
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- strict: Literal[True],
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- asyncutils.iters.azip(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- strict: Literal[True],
- asyncutils.iters.azip(
- *its: asyncutils._internal.types.SupportsIteration[T],
- strict: bool = ...,
Async version of
zipthat is not a class.
- asyncutils.iters.aziplongest[T](i1: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[tuple[T]][source]¶
- asyncutils.iters.aziplongest(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- /,
- *,
- fillvalue: object = ...,
- asyncutils.iters.aziplongest(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- /,
- *,
- fillvalue: object = ...,
- asyncutils.iters.aziplongest(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- /,
- *,
- fillvalue: object = ...,
- asyncutils.iters.aziplongest(
- i1: asyncutils._internal.types.SupportsIteration[T],
- i2: asyncutils._internal.types.SupportsIteration[R],
- i3: asyncutils._internal.types.SupportsIteration[V],
- i4: asyncutils._internal.types.SupportsIteration[U],
- i5: asyncutils._internal.types.SupportsIteration[S],
- /,
- *,
- fillvalue: object = ...,
- asyncutils.iters.aziplongest(
- *its: asyncutils._internal.types.SupportsIteration[T],
- fillvalue: T = ...,
Async version of
itertools.zip_longestthat is not a class. The first overload does not acceptfillvalue, because passing it with only one iterable does not make sense.
- async asyncutils.iters.basic_collect[T](it: asyncutils._internal.types.SupportsIteration[T], n: int) list[T][source]¶
Return a list of the first
nitems in the (async) iterableit, signalling no error if there are not enough items.
- asyncutils.iters.batch[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int,
- *,
- item_timeout: float | None = ...,
- strict: bool = ...,
More flexible but slightly slower implementation of
batch2(), supporting timeouts waiting for each item, that raisesValueErrorinstead ofItemsExhaustedin the case of the length of the iterable being indivisible by the batch size.
- asyncutils.iters.batch2[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int,
- strict: Literal[True],
- asyncutils.iters.batch2(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int | None,
- strict: Literal[False] = ...,
Batch an (async) iterable into an async generator of lists. If
strict=Trueis specified, raiseItemsExhaustedon the last batch if it is discovered then that the iterable does not have enough items for a complete batch.
- asyncutils.iters.batch_process[T, R](
- items: asyncutils._internal.types.SupportsIteration[T],
- size: int,
- processor: collections.abc.Callable[[list[T]], collections.abc.Awaitable[R]],
Apply
processorto each batch of sizesizeinitemsand yield the results awaited.
- asyncutils.iters.buffer[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- maxsize: int = ...,
- *,
- timeout_get: float | None = ...,
- timeout_put: float | None = ...,
- cooldown: float = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- Buffer the given (async) iterable in an async generator, with an async queue as buffer of capacity
maxsize(default unbounded) and optional timeouts for getting and putting items into the buffer.cooldownspecifies how long to wait after hitting a get timeout before trying again; whereas when a put timeout is reached, the async generator finishes.
- asyncutils.iters.empty_agen() collections.abc.AsyncGenerator[Never][source]¶
Return an async generator that yields nothing. Due to async generator finalization issues, this is not a constant like
yield_to_event_loop.
- async asyncutils.iters.fmap[T, **P](
- fs: asyncutils._internal.types.SupportsIteration[collections.abc.Callable[P, collections.abc.Awaitable[T]]],
- /,
- *a: P,
- **k: P,
Return a list of the results of calling each async function in the first argument (an (async) iterable of functions), with the provided arguments.
- asyncutils.iters.fmap_parallel[T, **P](
- fs: asyncutils._internal.types.SupportsIteration[collections.abc.Callable[P, collections.abc.Awaitable[T]]],
- /,
- *a: P,
- **k: P,
Like
fmap_sequential(), but starts background tasks for each call.
- asyncutils.iters.fmap_sequential[T, **P](
- fs: asyncutils._internal.types.SupportsIteration[collections.abc.Callable[P, collections.abc.Awaitable[T]]],
- /,
- *a: P,
- **k: P,
Like
fmap(), but only call a function after the last completes and the result is gotten.
- asyncutils.iters.iter_task[I: asyncutils._internal.types.SupportsIteration[object]](it: I, summaryf: collections.abc.Callable[[I], collections.abc.Awaitable[Any]] = ...) asyncio.Task[float][source]¶
Return a task that calls
summaryfon the passed (async) iterable and returns the time taken to run it. By default,summaryfconsumesitfully.
- asyncutils.iters.map_on_map[T, R, V](
- outer: collections.abc.Callable[[R], V],
- inner: collections.abc.Callable[[T], asyncutils._internal.types.SupportsIteration[R]],
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- inner_await: Literal[False] = ...,
- outer_await: Literal[False] = ...,
- asyncutils.iters.map_on_map(
- outer: collections.abc.Callable[[R], collections.abc.Awaitable[V]],
- inner: collections.abc.Callable[[T], asyncutils._internal.types.SupportsIteration[R]],
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- inner_await: Literal[False] = ...,
- outer_await: Literal[True],
- asyncutils.iters.map_on_map(
- outer: collections.abc.Callable[[R], V],
- inner: collections.abc.Callable[[T], collections.abc.Awaitable[asyncutils._internal.types.SupportsIteration[R]]],
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- inner_await: Literal[True],
- outer_await: Literal[False] = ...,
- asyncutils.iters.map_on_map(
- outer: collections.abc.Callable[[R], collections.abc.Awaitable[V]],
- inner: collections.abc.Callable[[T], collections.abc.Awaitable[asyncutils._internal.types.SupportsIteration[R]]],
- it: asyncutils._internal.types.SupportsIteration[T],
- *,
- inner_await: Literal[True],
- outer_await: Literal[True],
Apply a transformation on an (async) iterable on top of another.
- asyncutils.iters.mat_vec_mul(
- M: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
- V: asyncutils._internal.types.SupportsIteration[int],
Multiplication of a matrix
Mand a vectorV. O(n^2).
- asyncutils.iters.merge[T](
- *I: asyncutils._internal.types.SupportsIteration[T],
- reverse: bool = ...,
- maxqsize: int = ...,
- Merge items from the (async) iterables into a single async generator, according to the order in which they come.If
reverseisTrue, the order is reversed, but the returned generator only starts when all items are available.maxqsize(defaultcontext.MERGE_DEFAULT_MAX_QSIZE) controls the maximum number of items the consumer can fall behindthe producers before the producers cease to be advanced.Caution
If
maxqsizeis smaller than the total number of items in the sources in reverse mode, a deadlock will occur.
- asyncutils.iters.tee[T](it: asyncutils._internal.types.SupportsIteration[T], n: Literal[1]) tuple[collections.abc.AsyncGenerator[T]][source]¶
- asyncutils.iters.tee(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: Literal[2] = ...,
- *,
- maxqsize: int = ...,
- put_exc: bool = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- asyncutils.iters.tee(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: Literal[3],
- *,
- maxqsize: int = ...,
- put_exc: bool = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- asyncutils.iters.tee(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: Literal[4],
- *,
- maxqsize: int = ...,
- put_exc: bool = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- asyncutils.iters.tee(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: Literal[5],
- *,
- maxqsize: int = ...,
- put_exc: bool = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- asyncutils.iters.tee(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: Literal[6],
- *,
- maxqsize: int = ...,
- put_exc: bool = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- asyncutils.iters.tee(
- it: asyncutils._internal.types.SupportsIteration[T],
- n: int,
- *,
- maxqsize: int = ...,
- put_exc: bool = ...,
- loop: asyncio.AbstractEventLoop | None = ...,
- Create
nindependent async generators from a single (async) iterableitthat yield the same items, caching items in a queue when needed.A background task will be spawned to consume the iterable.Unlikeitertools.tee(), the returned iterators are plain async generators, and the flattening step with a linked list as specified in theitertoolsdocs is not done.maxqsize(defaultcontext.TEE_DEFAULT_MAX_QSIZE) specifies how many unproduced items can be consumed from the source ahead of theslowest consumer(s) before the background task and the faster consumers start blocking to wait for them. 0 or below indicates an unbounded queue.Ifput_excisTrue(defaultcontext.TEE_DEFAULT_PUT_EXC), an exception raised by the source iterable will be propagated as lateas possible; that is, only when the caller gets to that point. Slower consumers are not immediately affected.Otherwise, the exception will be raised in the background task used to consume the iterable, andQueueShutDownwill be propagatedto callers waiting on consumers.
- async asyncutils.iters.to_list[T](it: asyncutils._internal.types.SupportsIteration[T], /) list[T][source]¶
Collect all items of an async iterable into a list. Faster than
base.collect().
- async asyncutils.iters.to_set[H: collections.abc.Hashable](it: asyncutils._internal.types.SupportsIteration[H], /, frozen: Literal[False] = ...) set[H][source]¶
- async asyncutils.iters.to_set(it: asyncutils._internal.types.SupportsIteration[H], /, frozen: Literal[True]) frozenset[H]
Convert the output of
to_list()into a set or frozenset depending on thefrozenparameter (Falseby default).
- async asyncutils.iters.to_tuple[T](it: asyncutils._internal.types.SupportsIteration[T], /) tuple[T, Ellipsis][source]¶
Convert the output of
to_list()into a tuple.
- async asyncutils.iters.vecs_eq[T](
- u: asyncutils._internal.types.SupportsIteration[T],
- v: asyncutils._internal.types.SupportsIteration[T],
- cmpeq: collections.abc.Callable[[T, T], object] = ...,
- *,
- strict: bool = ...,
Whether the vectors
uandvare equal according tocmpeqcalled on each pair of items from iterating through them in parallel. IfstrictisFalse(defaultTrue), may returnTrueeven for differently-sized vectors.
- asyncutils.iters.window[T](
- it: asyncutils._internal.types.SupportsIteration[T],
- size: int,
- step: int = ...,
Window an async iterable into an async generator of tuples of the specified size and step. You can send in a tuple
(size, step)to change the behaviour of the iterator.