Skip to content

Comments

[Repo Assist] Add AsyncSeq.windowed for sliding-window combinators#241

Merged
dsyme merged 2 commits intomainfrom
repo-assist/improve-windowed-fd152e69801b31ac
Feb 24, 2026
Merged

[Repo Assist] Add AsyncSeq.windowed for sliding-window combinators#241
dsyme merged 2 commits intomainfrom
repo-assist/improve-windowed-fd152e69801b31ac

Conversation

@github-actions
Copy link
Contributor

🤖 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 to Seq.windowed.

Each call yields overlapping windows of windowSize elements as immutable 'T[] snapshots:

asyncSeq { yield 1; yield 2; yield 3; yield 4; yield 5 }
|> AsyncSeq.windowed 3
|> AsyncSeq.toListSynchronously
// [[|1;2;3|]; [|2;3;4|]; [|3;4;5|]]

Notable properties (matching Seq.windowed):

  • Yields the first window once windowSize elements have been consumed, then slides one element at a time.
  • Returns an empty sequence if the source has fewer than windowSize elements.
  • Raises ArgumentException if windowSize < 1.
  • AsyncSeq.pairwise is a special case equivalent to AsyncSeq.windowed 2 (but returning tuples instead of arrays).

Implementation

Uses System.Collections.Generic.Queue<'T> with an initial capacity of windowSize so each element costs one O(1) enqueue + one O(1) dequeue (when the window is full).

Motivation

Seq.windowed is a standard F# core library function. Its absence from AsyncSeq is 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:

  1. Empty source → empty result
  2. Source shorter than window → empty result
  3. Source exactly equal to window size → single window
  4. Sliding windows (5 elements, window=3 → 3 windows)
  5. Window size 1 → each element as a singleton array
  6. Window size 2 → equivalent to pairwise as arrays
  7. Window size 0 → ArgumentException

Generated by Repo Assist

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@ee50a3b7d1d3eb4a8c409ac9409fd61c9a66b0f5. View source at https://github.com/githubnext/agentics/tree/ee50a3b7d1d3eb4a8c409ac9409fd61c9a66b0f5/workflows/repo-assist.md.

Generated by Repo Assist

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@828ac109efb43990f59475cbfce90ede5546586c. View source at https://github.com/githubnext/agentics/tree/828ac109efb43990f59475cbfce90ede5546586c/workflows/repo-assist.md.

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>
@github-actions
Copy link
Contributor Author

✅ Pull request created: #241

@dsyme dsyme marked this pull request as ready for review February 24, 2026 02:20
@dsyme dsyme merged commit 2194542 into main Feb 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant