Work that has to be handed out in batches, such as database queries with a
limit on how many values an IN clause takes or an API that accepts at most a
hundred items per call, needs a slice cut into pieces of a fixed size, and the
index arithmetic for the short final piece is easy to get subtly wrong. One
tested version here removes that risk from every caller.
Definition of done: ChunkStrings(input []string, size int) [][]string returns
the values of input in consecutive slices of at most size elements, with the
last one holding whatever is left over, and returns nil when size is less than
one or the input is empty. It has a doc comment and table-driven tests covering
an exact multiple of the size, a remainder, a size larger than the input, a
size of one, a size of zero, a negative size, and an empty input.
Model: opus-5
Work that has to be handed out in batches, such as database queries with a
limit on how many values an `IN` clause takes or an API that accepts at most a
hundred items per call, needs a slice cut into pieces of a fixed size, and the
index arithmetic for the short final piece is easy to get subtly wrong. One
tested version here removes that risk from every caller.
Definition of done: `ChunkStrings(input []string, size int) [][]string` returns
the values of input in consecutive slices of at most size elements, with the
last one holding whatever is left over, and returns nil when size is less than
one or the input is empty. It has a doc comment and table-driven tests covering
an exact multiple of the size, a remainder, a size larger than the input, a
size of one, a size of zero, a negative size, and an empty input.
Model: opus-5
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Work that has to be handed out in batches, such as database queries with a
limit on how many values an
INclause takes or an API that accepts at most ahundred items per call, needs a slice cut into pieces of a fixed size, and the
index arithmetic for the short final piece is easy to get subtly wrong. One
tested version here removes that risk from every caller.
Definition of done:
ChunkStrings(input []string, size int) [][]stringreturnsthe values of input in consecutive slices of at most size elements, with the
last one holding whatever is left over, and returns nil when size is less than
one or the input is empty. It has a doc comment and table-driven tests covering
an exact multiple of the size, a remainder, a size larger than the input, a
size of one, a size of zero, a negative size, and an empty input.
Model: opus-5