Skip to content
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

slice: rework Batches and Chunks to return iterators #21

Merged
merged 1 commit into from
Jan 29, 2025
Merged

Conversation

creachadair
Copy link
Owner

Instead of a slice of results, return a single-valued iterator over the
selected components. A caller who wants the actual slices can use the
slices.Collect helper:

old := slice.Batches(vs, n)
new := slices.Collect(slice.Batches(vs, n))

Existing use in the target of a range do not need to change, except for
updating the target variables:

for _, c := range slice.Chunks(vs, n) {

becomes

for c := range slice.Chunks(vs, n) {

Instead of a slice of results, return a single-valued iterator over the
selected components. A caller who wants the actual slices can use the
slices.Collect helper:

    old := slice.Batches(vs, n)
    new := slices.Collect(slice.Batches(vs, n))

Existing use in the target of a range do not need to change, except for
updating the target variables:

    for _, c := range slice.Chunks(vs, n) {

becomes

    for c := range slice.Chunks(vs, n) {
@creachadair creachadair merged commit 5d31fc8 into main Jan 29, 2025
1 check passed
@creachadair creachadair deleted the mjf/iter branch January 29, 2025 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant