Add Take, Concat, Zip, Flatten, and other missing sequence functions #minor - #13
Merged
Conversation
…nctions Fills gaps in the API around bounded/unbounded sequences, combining sequences, deduplication, grouping, and numeric aggregation, following the existing dual iter.Seq/iter.Seq2 pattern. Also fixes a dead post-yield check in EveryUntil that meant it never re-evaluated the clock after a slow consumer. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the seq package’s iterator API by adding a set of commonly expected sequence operations (taking/dropping prefixes, combining sequences, flattening/flat-mapping, grouping/deduping, predicates, numeric aggregates, and utilities), and it fixes a timing bug in EveryUntil so slow consumers can terminate without waiting for an extra tick. It also updates documentation and adds regression/stress coverage for newly introduced edge cases.
Changes:
- Add new exported sequence helpers (e.g.,
Take*,Concat*,Zip,Merge*,Flatten*,Unique*,Windows*,All/None,Sum/Product/Average,Last*,Scan*,Cycle*,SwapKV,Tap*,FromChanCtx,Enumerate). - Fix
EveryUntilto re-check the clock after yielding so slow consumers don’t wait for an extra tick. - Add stresstests for new panic/termination/cancellation behaviors and update README API surface.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
stresstest/stress_test.go |
Adds regression/stress tests for new edge cases (panics, hangs, cancellation). |
seq.go |
Implements new exported sequence operations and adjusts EveryUntil behavior. |
seq_test.go |
Adds/updates executable examples demonstrating new APIs and EveryUntil behavior. |
README.md |
Documents the expanded API surface and new exported types/constraints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ng tests - FromChanCtx now checks the context with a non-blocking select before the blocking receive, matching ToChanCtx: an already-canceled context wins over a ready channel instead of racing it. - ExampleEveryUntil no longer asserts on real-time tick delivery (it could observe zero ticks on a loaded machine); it now breaks on the first tick under a generous deadline. - The exact timing behaviors moved to stresstest on a testing/synctest fake clock: exact tick counts for EveryUntil/EveryN, and the slow-iteratee early-end regression now asserts precise elapsed fake time. - TestFromChanCtxCancelUnblocks converted to synctest (a hang now fails as a bubble deadlock instead of a real 5s timeout) and a new regression test covers cancellation priority over a ready channel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Take,TakeWhile,DropWhile, ...), combining sequences (Concat,Zip,Merge), flattening (Flatten,FlatMap), dedup/grouping (Unique,GroupBy,Partition,Windows), predicates (All,None), numeric aggregation (Sum,Product,Average), and misc utilities (Last,Scan,Cycle,SwapKV,Tap,FromChanCtx,Enumerate). Every function follows the existing dualiter.Seq/iter.Seq2(KV) pattern and lazy-closure style.EveryUntil(it re-checked the samenowalready checked before the yield instead of the current clock), so a slow consumer now correctly ends the sequence instead of waiting for another tick.Test plan
go test -v -race ./...go vet ./...staticcheck ./...stresstest, per this repo's convention)stresstestregressions:Windows/WindowsKVpanic on non-positive size,Cycle/CycleKVterminate on empty input instead of hanging,FromChanCtxunblocks on context cancellation🤖 Generated with Claude Code