Utility batching function.
(size: int, iterable: Iterable[T])
| 122 | |
| 123 | |
| 124 | def _batch(size: int, iterable: Iterable[T]) -> Iterator[List[T]]: |
| 125 | """Utility batching function.""" |
| 126 | it = iter(iterable) |
| 127 | while True: |
| 128 | chunk = list(islice(it, size)) |
| 129 | if not chunk: |
| 130 | return |
| 131 | yield chunk |
| 132 | |
| 133 | |
| 134 | async def _abatch(size: int, iterable: AsyncIterable[T]) -> AsyncIterator[List[T]]: |