Add ChunkStrings to split a string slice into fixed-size batches #4
Reference in New Issue
Block a user
Delete Branch "clawbot/util:proposal-chunk-strings"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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