[Repo Assist] Add AsyncSeq.windowed for sliding-window combinators#241
Merged
[Repo Assist] Add AsyncSeq.windowed for sliding-window combinators#241
Conversation
Adds AsyncSeq.windowed : int -> AsyncSeq<'T> -> AsyncSeq<'T[]> This is a sliding-window combinator analogous to Seq.windowed and Seq.pairwise (which is a special case with windowSize=2). Each window is yielded as an immutable array snapshot; the window slides one element at a time. Implementation uses a Queue<'T> of capacity windowSize to maintain the current window with O(1) enqueue/dequeue per element. Includes 7 tests covering: empty source, source shorter than window, exact-size source, sliding windows, size-1, size-2, and ArgumentException for windowSize < 1. All 201 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
✅ Pull request created: #241 |
6 tasks
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Adds
AsyncSeq.windowed : windowSize:int -> source:AsyncSeq<'T> -> AsyncSeq<'T []>— a sliding-window combinator analogous toSeq.windowed.Each call yields overlapping windows of
windowSizeelements as immutable'T[]snapshots:Notable properties (matching
Seq.windowed):windowSizeelements have been consumed, then slides one element at a time.windowSizeelements.ArgumentExceptionifwindowSize < 1.AsyncSeq.pairwiseis a special case equivalent toAsyncSeq.windowed 2(but returning tuples instead of arrays).Implementation
Uses
System.Collections.Generic.Queue<'T>with an initial capacity ofwindowSizeso each element costs one O(1) enqueue + one O(1) dequeue (when the window is full).Motivation
Seq.windowedis a standard F# core library function. Its absence fromAsyncSeqis a gap users commonly encounter when porting sequential code to async streaming — e.g. computing moving averages, detecting consecutive patterns, or correlating adjacent frames. This PR fills that gap with minimal surface area.Test Status
✅ All 201 tests pass (
dotnet test). 7 new tests cover:pairwiseas arraysArgumentException