mode.utils.aiter
Async iterator lost and found missing methods: aiter, anext, etc.
AsyncIterWrapper
Bases: AsyncIterator[T]
Wrap regular Iterator into an AsyncIterator.
Source code in mode/utils/aiter.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
arange
Bases: AsyncIterable[int]
Async generator that counts like range
.
Source code in mode/utils/aiter.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
aenumerate(it, start=0)
async
async for
version of enumerate
.
Source code in mode/utils/aiter.py
32 33 34 35 36 37 38 39 |
|
aiter(it)
Create iterator from iterable.
Notes
If the object is already an iterator, the iterator
should return self when __aiter__
is called.
Source code in mode/utils/aiter.py
61 62 63 64 65 66 67 68 69 |
|
alist(ait)
async
Convert async generator to list.
Source code in mode/utils/aiter.py
139 140 141 |
|
anext(it, *default)
async
Get next value from async iterator, or default
if empty.
Raises:
Type | Description |
---|---|
exc: |
Source code in mode/utils/aiter.py
84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
aslice(ait, *slice_args)
async
Extract slice from async generator.
Source code in mode/utils/aiter.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
chunks(it, n)
async
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]]
Source code in mode/utils/aiter.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|