Skip to content

Commit 46c5f39

Browse files
refactor: simplify splitAt 'rest' taskSeq to use while!
The 'rest' sequence returned by splitAt used a manual go2 flag and an explicit MoveNextAsync pre-advance before its loop. This is equivalent to a direct 'while! e.MoveNextAsync() do yield e.Current' guarded by the existing 'go' flag (which tracks whether the source was exhausted while filling 'first'). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9984a8b commit 46c5f39

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

release-notes.txt

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

44
Unreleased
5+
- refactor: simplify splitAt 'rest' taskSeq to use while!, removing redundant go2 mutable and manual MoveNextAsync pre-advance
56

67
1.1.1
78
- perf: use while! in groupBy, countBy, partition, except, exceptOfSeq to eliminate redundant mutable 'go' variables and initial MoveNextAsync calls

src/FSharp.Control.TaskSeq/TaskSeqInternal.fs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -848,18 +848,12 @@ module internal TaskSeqInternal =
848848
else
849849
go <- false
850850

851-
// 'rest' captures 'e' from the outer task block, following the same pattern as tryTail.
851+
// 'rest' captures 'e' from the outer task block; if the source was not exhausted,
852+
// advance once past the last element added to 'first', then yield the remainder.
852853
let rest = taskSeq {
853-
let mutable go2 = go
854-
855-
if go2 then
856-
let! step = e.MoveNextAsync()
857-
go2 <- step
858-
859-
while go2 do
860-
yield e.Current
861-
let! step = e.MoveNextAsync()
862-
go2 <- step
854+
if go then
855+
while! e.MoveNextAsync() do
856+
yield e.Current
863857
}
864858

865859
return first.ToArray(), rest

0 commit comments

Comments
 (0)