Skip to content

[Repo Assist] feat: add TaskSeq.mapFold and TaskSeq.mapFoldAsync (56 tests)#306

Merged
dsyme merged 3 commits intomainfrom
repo-assist/feat-mapfold-2026-03-4abf0aa06ea5d884
Mar 8, 2026
Merged

[Repo Assist] feat: add TaskSeq.mapFold and TaskSeq.mapFoldAsync (56 tests)#306
dsyme merged 3 commits intomainfrom
repo-assist/feat-mapfold-2026-03-4abf0aa06ea5d884

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.mapFold and TaskSeq.mapFoldAsync, which combine a map and a fold in a single pass over a task sequence — mirroring List.mapFold, Array.mapFold, and Seq.mapFold from FSharp.Core.

Signature

TaskSeq.mapFold :
    mapping: ('State -> 'T -> 'Result * 'State)
    -> state: 'State
    -> source: TaskSeq<'T>
    -> Task<'Result[] * 'State>

TaskSeq.mapFoldAsync :
    mapping: ('State -> 'T -> #Task<'Result * 'State>)
    -> state: 'State
    -> source: TaskSeq<'T>
    -> Task<'Result[] * 'State>

The mapping function receives the current state and element, returns a mapped result and a new state. All elements are consumed eagerly (like List.mapFold), producing an array of results and the final state.

Changes

  • TaskSeqInternal.fs: new MapFolderAction struct DU; mapFold internal implementation using a ResizeArray collector
  • TaskSeq.fs: two delegating members (mapFold, mapFoldAsync)
  • TaskSeq.fsi: full XML doc-comment signatures for both members
  • TaskSeq.MapFold.Tests.fs: 56 tests across EmptySeq, Functionality, and SideEffects modules — including parity test against List.mapFold
  • release-notes.txt: updated for 0.5.0

Trade-offs

  • Result is 'Result[] (not TaskSeq<'Result>) because the final state is only known after the full sequence is consumed. This matches FSharp.Core's eager semantics for mapFold.
  • A lazy variant yielding (TaskSeq<'Result> * Task<'State>) is theoretically possible but would require buffering or two-pass consumption, and would diverge from idiomatic F# usage.

Test Status

✅ Build succeeded (0 warnings, 0 errors)
✅ All 56 new mapFold/mapFoldAsync tests pass
✅ Full test suite: 3906 passed, 2 skipped (infra), 0 failed
✅ Fantomas format check passes

Generated by Repo Assist ·

To install this agentic workflow, run

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

Implements TaskSeq.mapFold and TaskSeq.mapFoldAsync, which apply a
mapping function that both transforms each element and threads an
accumulator state through the sequence in a single pass. The result
is a pair of a 'Result array and the final 'State, mirroring
List.mapFold, Array.mapFold, and Seq.mapFold from FSharp.Core.

- Adds MapFolderAction DU type to TaskSeqInternal.fs
- Adds mapFold internal implementation (eager, collects to array)
- Exposes TaskSeq.mapFold / TaskSeq.mapFoldAsync on the public type
- Adds signatures to TaskSeq.fsi with full XML doc comments
- Adds 56 tests covering: empty, single element, multi-element,
  state threading order, side-effect variants, parity with List.mapFold
- Updates release notes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 7, 2026 23:46
@dsyme dsyme merged commit 25abafe into main Mar 8, 2026
4 checks passed
@dsyme dsyme deleted the repo-assist/feat-mapfold-2026-03-4abf0aa06ea5d884 branch March 8, 2026 01:51
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