Skip to content

Commit bc60302

Browse files
authored
Merge pull request #393 from fsprojects/repo-assist/refactor-splitAt-rest-while-bang-20260418-0388821e31824de0
[Repo Assist] refactor: simplify splitAt 'rest' taskSeq to use while!
2 parents 9984a8b + 12069f2 commit bc60302

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

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)