mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 17:34:32 +02:00
utils.chunks() is now a documented API, closes #451
This commit is contained in:
parent
015c663464
commit
e10536c7f5
2 changed files with 14 additions and 1 deletions
|
|
@ -94,3 +94,10 @@ sqlite_utils.utils.TypeTracker
|
|||
|
||||
.. autoclass:: sqlite_utils.utils.TypeTracker
|
||||
:members: wrap, types
|
||||
|
||||
.. _reference_utils_chunks:
|
||||
|
||||
sqlite_utils.utils.chunks
|
||||
-------------------------
|
||||
|
||||
.. autofunction:: sqlite_utils.utils.chunks
|
||||
|
|
|
|||
|
|
@ -468,7 +468,13 @@ def _compile_code(code, imports, variable="value"):
|
|||
return locals["fn"]
|
||||
|
||||
|
||||
def chunks(sequence, size):
|
||||
def chunks(sequence: Iterable, size: int) -> Iterable[Iterable]:
|
||||
"""
|
||||
Iterate over chunks of the sequence of the given size.
|
||||
|
||||
:param sequence: Any Python iterator
|
||||
:param size: The size of each chunk
|
||||
"""
|
||||
iterator = iter(sequence)
|
||||
for item in iterator:
|
||||
yield itertools.chain([item], itertools.islice(iterator, size - 1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue