Skip to content

Add Take, Concat, Zip, Flatten, and other missing sequence functions #minor - #13

Merged
freeformz merged 2 commits into
mainfrom
add-missing-seq-functions
Jul 3, 2026
Merged

Add Take, Concat, Zip, Flatten, and other missing sequence functions #minor#13
freeformz merged 2 commits into
mainfrom
add-missing-seq-functions

Conversation

@freeformz

Copy link
Copy Markdown
Owner

Summary

  • Adds ~40 new exported functions closing gaps in the iterator API: bounded/prefix operations (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 dual iter.Seq/iter.Seq2 (KV) pattern and lazy-closure style.
  • Fixes a dead post-yield time check in EveryUntil (it re-checked the same now already checked before the yield instead of the current clock), so a slow consumer now correctly ends the sequence instead of waiting for another tick.
  • Updates README with the new API surface.

Test plan

  • go test -v -race ./...
  • go vet ./...
  • staticcheck ./...
  • Coverage raised from 90.1% to 99.1% (remaining gap is panic-guard lines covered by stresstest, per this repo's convention)
  • New stresstest regressions: Windows/WindowsKV panic on non-positive size, Cycle/CycleKV terminate on empty input instead of hanging, FromChanCtx unblocks on context cancellation

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings July 3, 2026 21:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EveryUntil to 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.

Comment thread seq.go
Comment thread seq_test.go Outdated
Comment thread seq.go
…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>
@freeformz
freeformz merged commit 64337b3 into main Jul 3, 2026
14 checks passed
@freeformz
freeformz deleted the add-missing-seq-functions branch July 3, 2026 21:50
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.

2 participants