Adds ChunkStrings(input []string, size int) [][]string, which returns the
values of the input in consecutive slices of at most size elements. The last
slice holds the remainder. A size below one, or an empty input, returns nil.
This belongs here because handing work out in batches is a constant need, from
splitting a list for an API that accepts a limited number of items per call to
paging through a set of identifiers, and the standard library of this module's
Go version has nothing for it. The arithmetic for the short final piece is
small but easy to get wrong once per project.
Things to know:
Each returned slice is a copy rather than a view into the input. Slicing the
input in place would be cheaper, but then appending to one piece could
silently overwrite the start of the next one, which is a nasty surprise.
The code is in a new file, chunk.go, rather than appended to util.go, so
that the ten proposal branches do not all conflict in the same place.
make test on this branch reports one failure, TestNowUnixMicro. That test
already fails on master and is unrelated to this change.
Model: opus-5
Adds `ChunkStrings(input []string, size int) [][]string`, which returns the
values of the input in consecutive slices of at most `size` elements. The last
slice holds the remainder. A size below one, or an empty input, returns nil.
This belongs here because handing work out in batches is a constant need, from
splitting a list for an API that accepts a limited number of items per call to
paging through a set of identifiers, and the standard library of this module's
Go version has nothing for it. The arithmetic for the short final piece is
small but easy to get wrong once per project.
Things to know:
- Each returned slice is a copy rather than a view into the input. Slicing the
input in place would be cheaper, but then appending to one piece could
silently overwrite the start of the next one, which is a nasty surprise.
- The code is in a new file, `chunk.go`, rather than appended to `util.go`, so
that the ten proposal branches do not all conflict in the same place.
- `make test` on this branch reports one failure, `TestNowUnixMicro`. That test
already fails on `master` and is unrelated to this change.
Model: opus-5
clawbot
self-assigned this 2026-09-05 05:24:33 +02:00
ChunkStrings cuts a slice into consecutive pieces of at most the requested
size, with the leftovers in the last piece, and returns copies so the pieces
cannot disturb each other. Comes with a doc comment and table-driven tests.
(closes#3)
Model: opus-5
sneak
merged commit 2d714eea9f into master2026-09-05 05:46:04 +02:00
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.
Adds
ChunkStrings(input []string, size int) [][]string, which returns thevalues of the input in consecutive slices of at most
sizeelements. The lastslice holds the remainder. A size below one, or an empty input, returns nil.
This belongs here because handing work out in batches is a constant need, from
splitting a list for an API that accepts a limited number of items per call to
paging through a set of identifiers, and the standard library of this module's
Go version has nothing for it. The arithmetic for the short final piece is
small but easy to get wrong once per project.
Things to know:
input in place would be cheaper, but then appending to one piece could
silently overwrite the start of the next one, which is a nasty surprise.
chunk.go, rather than appended toutil.go, sothat the ten proposal branches do not all conflict in the same place.
make teston this branch reports one failure,TestNowUnixMicro. That testalready fails on
masterand is unrelated to this change.Model: opus-5