Skip to content

[Repo Assist] feat: add TaskSeq.reduce and TaskSeq.reduceAsync (ref #289)#299

Merged
dsyme merged 2 commits intomainfrom
repo-assist/feat-reduce-2026-03-4df851dee5ec5f9d
Mar 7, 2026
Merged

[Repo Assist] feat: add TaskSeq.reduce and TaskSeq.reduceAsync (ref #289)#299
dsyme merged 2 commits intomainfrom
repo-assist/feat-reduce-2026-03-4df851dee5ec5f9d

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 TaskSeq.reduce and TaskSeq.reduceAsync — fold-without-initial-state operations that use the first element as the accumulator seed, matching the semantics of Seq.reduce and AsyncSeq.reduce.

Part of the work to align with FSharp.Control.AsyncSeq (ref #289). Please do not close #289 as this is one PR of several.


Implementation

Root cause / motivation

TaskSeq.fold requires an explicit initial state. For cases where the element type and state type are the same (e.g. summing, string concatenation, taking max), reduce is the idiomatic operation — no seed needed.

Changes

File Change
TaskSeqInternal.fs New reduce function: reads first element, raises on empty, folds rest
TaskSeq.fs Expose reduce / reduceAsync dispatching to FolderAction / AsyncFolderAction
TaskSeq.fsi XML-doc signatures for both members
TaskSeq.Reduce.Tests.fs 75 new tests (new file)
FSharp.Control.TaskSeq.Test.fsproj Register test file

Semantics

  • Raises ArgumentException when the sequence is empty (mirrors Seq.reduce)
  • The folder is called exactly n − 1 times for a sequence of n elements
  • For a singleton, the single element is returned without calling the folder

Test Status

Build: ✅ succeeded (0 warnings, 0 errors)
Tests: ✅ 75/75 passed
Fantomas: ✅ clean after formatting

Test categories:

  • Null/empty guards (ArgumentNullException, ArgumentException)
  • Singleton: folder not called, correct value returned
  • Call-count verification (n−1 calls for n elements)
  • Correct numeric sum (1..10 → 55)
  • String concatenation (chars A..J)
  • Side-effecting sequences (second enumeration picks up next batch)

Generated by Repo Assist ·

To install this agentic workflow, run

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

Adds two new combinators that fold a task sequence without requiring
an explicit initial state — the first element is used instead. Raises
ArgumentException on an empty sequence, matching Seq.reduce semantics.

- TaskSeq.reduce    : synchronous folder
- TaskSeq.reduceAsync: asynchronous folder

75 new tests covering: null/empty guards, singleton sources, call-count
verification (folder called n-1 times), string concatenation, and
side-effecting sequences.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 7, 2026 22:03
@dsyme dsyme merged commit 0bdf1d6 into main Mar 7, 2026
4 checks passed
@dsyme dsyme deleted the repo-assist/feat-reduce-2026-03-4df851dee5ec5f9d branch March 7, 2026 22:08
github-actions bot pushed a commit that referenced this pull request Mar 7, 2026
…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>
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.

Align set of supported functions with latest FSharp.Control.AsyncSeq

1 participant