mode.utils.aiter
¶
Async iterator lost and found missing methods: aiter, anext, etc.
-
mode.utils.aiter.
aenumerate
(it: AsyncIterable[T], start: int = 0) → AsyncIterator[Tuple[int, T]]¶ async for
version ofenumerate
.
-
mode.utils.aiter.
aiter
(it: Any) → AsyncIterator[T]¶ Create iterator from iterable.
Notes
If the object is already an iterator, the iterator should return self when
__aiter__
is called.
-
async
mode.utils.aiter.
anext
(it: AsyncIterator[T], *default: Optional[T]) → T¶ Get next value from async iterator, or default if empty.
- Raises
StopAsyncIteration – if default is not defined and the async iterator is fully consumed.
-
class
mode.utils.aiter.
arange
(*slice_args: Optional[int], **slice_kwargs: Optional[int])¶ Async generator that counts like
range
.-
count
(n: int) → int¶
-
index
(n: int) → int¶
-
-
async
mode.utils.aiter.
alist
(ait: AsyncIterator[T]) → List[T]¶ Convert async generator to list.
-
mode.utils.aiter.
aslice
(ait: AsyncIterator[T], *slice_args: int) → AsyncIterator[T]¶ Extract slice from async generator.
-
mode.utils.aiter.
chunks
(it: AsyncIterable[T], n: int) → AsyncIterable[List[T]]¶ Split an async iterator into chunks with n elements each.
Example
# n == 2 >>> x = chunks(arange(10), 2) >>> [item async for item in x] [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]
# n == 3 >>> x = chunks(arange(10)), 3) >>> [item async for item in x] [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]