Skip to content

feat: support for buffer iterator#824

Merged
samber merged 4 commits intosamber:masterfrom
mimol91:buffer
Mar 2, 2026
Merged

feat: support for buffer iterator#824
samber merged 4 commits intosamber:masterfrom
mimol91:buffer

Conversation

@mimol91
Copy link
Contributor

@mimol91 mimol91 commented Mar 2, 2026

Add support for Buffer in it sub package

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.15%. Comparing base (14fff24) to head (bad6adf).
⚠️ Report is 44 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #824      +/-   ##
==========================================
+ Coverage   92.11%   92.15%   +0.04%     
==========================================
  Files          32       32              
  Lines        4259     4271      +12     
==========================================
+ Hits         3923     3936      +13     
  Misses        252      252              
+ Partials       84       83       -1     
Flag Coverage Δ
unittests 92.15% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber
Copy link
Owner

samber commented Mar 2, 2026

I would change the control flow: channel is push-based vs iterators are pull-based.

func Buffer[T any](seq iter.Seq[T], size int) iter.Seq[[]T] {
      return func(yield func([]T) bool) {
            buffer := make([]T, 0, size)

            seq(func(v T) bool {
                  buffer = append(buffer, v)
                  if len(buffer) < size {
                      return true  // keep pulling
                  }
                  // Buffer full, yield it
                  result := buffer
                  buffer = make([]T, 0, size)  // allocate new buffer
                  return yield(result)  // false = stop, true = continue
            })

            // Yield remaining partial buffer
            if len(buffer) > 0 {
                yield(buffer)
            }
      }
}

WDYT?

EDIT: SeqToChannel could make the transformation from channel to seq.

EDIT2: i'm doing the change by myself since i would like to release the next version of lo today

@samber samber merged commit 56ef3be into samber:master Mar 2, 2026
13 checks passed
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.

3 participants