def batched_it(iterable: Iterable[_T_co], n: int) -> Iterator[Iterator[_T_co]]:
    """Batch data into iterators of length n. The last batch may be shorter."""
    # batched('ABCDEFG', 3) --> ABC DEF G
    if n < 1:
        raise ValueError("Batch size must be at least one")
    it = iter(iterable)
    while True:
        chunk_it = islice(it, n)
        try:
            first_el = next(chunk_it)
        except StopIteration:
            return
        yield chain((first_el,), chunk_it)
Batch data into iterators of length n. The last batch may be shorter.
src/datachain/utils.py