Skip to content

Commit bbf9125

Browse files
author
Onur Gumus
committed
refactor: replace FoldStep DU with foldWhile predicate+folder API
Reworks the early-termination fold added in 7bde226 to match the conventions of FSharp.Control.TaskSeq: bool-returning predicate + plain folder, and no new public DU. Every other early-termination API in the library (takeWhile, skipWhile, tryFind, forall, exists) uses this shape; every DU in the source is internal. FoldStep<'State> would have been the only public DU, which is the inconsistency @dsyme flagged on the PR. API: - TaskSeq.foldWhile : ('State -> 'T -> bool) -> ('State -> 'T -> 'State) -> 'State -> TaskSeq<'T> -> Task<'State> - TaskSeq.foldWhileAsync : ('State -> 'T -> #Task<bool>) -> ('State -> 'T -> #Task<'State>) -> 'State -> TaskSeq<'T> -> Task<'State> Semantics (match takeWhile, exclusive): the predicate is evaluated against (currentState, nextElement) before that element is folded. If false, iteration halts without folding that element and the source is not enumerated further. Removes: - public FoldStep<'State> DU - internal FoldUntilAction DU - TaskSeq.foldUntil / foldUntilAsync Tests: rewritten for exclusive semantics (halting element not folded, predicate-call / folder-call counts asserted separately). Full test suite green (5277 passed).
1 parent 7bde226 commit bbf9125

File tree

7 files changed

+333
-284
lines changed

7 files changed

+333
-284
lines changed

release-notes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Release notes:
33

44
Unreleased
5-
- adds TaskSeq.foldUntil and TaskSeq.foldUntilAsync: fold with early termination via a FoldStep<'State> DU (Continue / Halt). The underlying sequence is not enumerated past the element that caused Halt.
5+
- adds TaskSeq.foldWhile and TaskSeq.foldWhileAsync: fold with early termination via a (state, element) -> bool predicate (takeWhile-style, exclusive). When the predicate returns false, iteration halts without folding that element; no further elements are enumerated.
66
- test: add SideEffects module and ImmTaskSeq variant tests to TaskSeq.ChunkBy.Tests.fs, improving coverage for chunkBy and chunkByAsync
77
- fixes: `Async.bind` signature corrected from `(Async<'T> -> Async<'U>)` to `('T -> Async<'U>)` to match standard monadic bind semantics (same as `Task.bind`); the previous signature made the function effectively equivalent to direct application
88
- refactor: simplify splitAt 'rest' taskSeq to use while!, removing redundant go2 mutable and manual MoveNextAsync pre-advance

src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<Compile Include="TaskSeq.FindIndex.Tests.fs" />
2929
<Compile Include="TaskSeq.Find.Tests.fs" />
3030
<Compile Include="TaskSeq.Fold.Tests.fs" />
31-
<Compile Include="TaskSeq.FoldUntil.Tests.fs" />
31+
<Compile Include="TaskSeq.FoldWhile.Tests.fs" />
3232
<Compile Include="TaskSeq.Scan.Tests.fs" />
3333
<Compile Include="TaskSeq.MapFold.Tests.fs" />
3434
<Compile Include="TaskSeq.Reduce.Tests.fs" />

src/FSharp.Control.TaskSeq.Test/TaskSeq.FoldUntil.Tests.fs

Lines changed: 0 additions & 226 deletions
This file was deleted.

0 commit comments

Comments
 (0)