aioplus.abatched¶
- aioplus.abatched(aiterable, /, *, n, strict=False)¶
Batch data from the aiterable into tuples of length
n.- Parameters:
aiterable (AsyncIterable of T) – An asynchronous iterable of elements to be grouped into batches.
n (int) – The batch size. Each tuple will contain up to
nelements.strict (bool, default False) – If
True, raises aValueErrorif the total number of objects is not divisible byn. IfFalse, the last batch may be shorter thann.
- Returns:
An asynchronous iterable yielding tuples of at most
nelements.- Return type:
AsyncIterable of tuple[T, …]
Examples
>>> aiterable = arange(23) >>> [batch async for batch in abatched(aiterable, n=3)] [(0, 1, 2), (3, 4, 5), ..., (18, 19, 20), (21, 22)]
Notes
The final batch may be shorter than
n, unlessstrictis set toTrue.
See also