-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add batch.BySize
function
#735
Conversation
lib/batch/batch.go
Outdated
|
||
// BySize takes a series of elements, encodes them, groups them into batches of bytes that sum to at most [maxSize], and | ||
// then passes each of those batches to the [yield] function. | ||
func BySize[T any](in []T, maxSize int, encode func(T) ([]byte, error), yield func([][]byte) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxSizeBytes?
} | ||
{ | ||
// Non-empty slice + all items exactly fit into just under one batch: | ||
batches, err := testBySize([]string{"foo", "bar", "baz", "qux"}, 13, goodEncoder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth adding a check on how many times goodEncoding
was called? Which will test how many times yield
was called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case goodEncoder
will be called once for each item (4 times) but yield
will be called once. The amount of times that yield
is called will always equal the length of batches
.
No description provided.