priority: medium

status: open

title: Implement settlement batch chunking

type: feature


current_content:
"""Batch chunking for nightly settlement."""

def chunk(items, size):
    """Split items into consecutive groups of at most `size`."""
    raise NotImplementedError

function: chunk

note: hidden tests also run at verification time and are not shown

service: payments

spec:
Implement chunk(items, size) returning a list of lists.

Settlement batches a day's captures so one long-tailed merchant cannot stall
the run. Split `items` into consecutive groups of at most `size`, preserving
order. The final group may be shorter. An empty input produces no groups at
all - not one empty group. A size below 1 is meaningless and must raise
ValueError.

`items` is whatever captures.list_settlable() returned, which is any iterable
and is sometimes a one-pass generator, so do not assume it can be indexed or
measured with len().


content:
"""Batch chunking for nightly settlement."""

def chunk(items, size):
    """Split items into consecutive groups of at most `size`."""
    if size < 1:
        raise ValueError('size must be >= 1')
    items = list(items)
    return [items[i:i + size] for i in range(0, len(items), size)]

next: run_exercise_tests to execute it


note: all visible tests pass; hidden tests also ran and are not shown