Skip to content

[Repo Assist] feat: add TaskSeq.chunkBySize and TaskSeq.windowed (closes #258, ref #289)#303

Merged
dsyme merged 3 commits intomainfrom
repo-assist/feat-windowed-chunkbysize-2026-03-3f5b2d6577426398
Mar 8, 2026
Merged

[Repo Assist] feat: add TaskSeq.chunkBySize and TaskSeq.windowed (closes #258, ref #289)#303
dsyme merged 3 commits intomainfrom
repo-assist/feat-windowed-chunkbysize-2026-03-3f5b2d6577426398

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 7, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Adds two sequence-segmentation combinators that were explicitly requested (see #258 and the closing comment on #265) and are part of the Seq API alignment tracked in #289.

TaskSeq.chunkBySize

Divides a task sequence into non-overlapping chunks of at most chunkSize elements. The last chunk may be smaller if the source does not divide evenly.

taskSeq { yield! [1..7] }
|> TaskSeq.chunkBySize 3
// → [| [|1;2;3|]; [|4;5;6|]; [|7|] |]

Performance: uses a fixed-size pre-allocated 'T[] buffer instead of a ResizeArray, avoiding resize allocations. One Array.copy per full chunk, one Array.sub for the last partial chunk.

TaskSeq.windowed

Returns overlapping sliding windows of exactly windowSize consecutive elements.

taskSeq { yield! [1..5] }
|> TaskSeq.windowed 3
// → [| [|1;2;3|]; [|2;3;4|]; [|3;4;5|] |]

Performance: maintains a ring buffer of size windowSize — each new element is written in O(1) at the current position. When a full window is ready, two Array.blit calls copy it in source order to a fresh result array, giving a single allocation per window with no redundant element movement.

Both functions:

  • Validate the size argument eagerly (before enumeration), raising ArgumentException for non-positive sizes — consistent with Seq.chunkBySize / Seq.windowed.
  • Include full XML doc comments in the .fsi signature file.

Other changes

Tests

TaskSeq.ChunkBySize.Tests.fs and TaskSeq.Windowed.Tests.fs171 new tests covering:

  • Null / invalid argument handling (eager throws)
  • Empty source variants (all TestEmptyVariants)
  • All TestImmTaskSeq variants: order preservation, chunk/window sizes, remainder, exact-size, larger-than-source
  • Array independence (mutating one chunk/window doesn't affect others)
  • Side-effect execution
  • Exception propagation from source
  • Ring-buffer correctness (explicit wrap-around test for windowed)

Test Status

✅ Build: succeeded (0 warnings, 0 errors) — verified locally against .NET SDK 10.0.102
✅ Tests: 4,021 passed, 2 skipped, 0 failed (full suite)
✅ Formatting: dotnet fantomas . --check passes

Note: global.json pins SDK 10.0.103; CI on windows-latest will run with the exact pinned version.

Closes #258

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ec7d342403c9912c87320110f8822a8fbb817a0c

…289)

- TaskSeq.chunkBySize: divides a task sequence into non-overlapping chunks of
  at most chunkSize elements. Uses a fixed-size array buffer (vs. ResizeArray)
  to avoid intermediate allocations and resizing.

- TaskSeq.windowed: returns overlapping sliding windows of a fixed size.
  Uses a ring buffer internally so that only a single allocation (per window)
  is needed; no redundant element copies on each step.

Both functions validate their size argument eagerly (before enumeration starts),
raise ArgumentException for non-positive sizes, and are fully documented in the
.fsi signature file.

Also:
- Update README.md to mark chunkBySize, windowed, pairwise, scan/scanAsync,
  reduce/reduceAsync, and unfold/unfoldAsync as implemented (these were merged
  in PRs #293, #296, #299, #300 respectively).
- Update release-notes.txt for 0.5.0.
- 171 new tests across TaskSeq.ChunkBySize.Tests.fs and TaskSeq.Windowed.Tests.fs.
  All 4021 existing tests continue to pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 7, 2026 22:41
@dsyme dsyme merged commit 7871669 into main Mar 8, 2026
4 checks passed
@dsyme dsyme deleted the repo-assist/feat-windowed-chunkbysize-2026-03-3f5b2d6577426398 branch March 8, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chunkBySize

1 participant