diff --git a/release-notes.txt b/release-notes.txt index 20ee8fb..ebaa6cc 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -2,6 +2,7 @@ Release notes: Unreleased + - refactor: simplify splitAt 'rest' taskSeq to use while!, removing redundant go2 mutable and manual MoveNextAsync pre-advance 1.1.1 - perf: use while! in groupBy, countBy, partition, except, exceptOfSeq to eliminate redundant mutable 'go' variables and initial MoveNextAsync calls diff --git a/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs b/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs index b935e13..7e73fb4 100644 --- a/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs +++ b/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs @@ -848,18 +848,12 @@ module internal TaskSeqInternal = else go <- false - // 'rest' captures 'e' from the outer task block, following the same pattern as tryTail. + // 'rest' captures 'e' from the outer task block; if the source was not exhausted, + // advance once past the last element added to 'first', then yield the remainder. let rest = taskSeq { - let mutable go2 = go - - if go2 then - let! step = e.MoveNextAsync() - go2 <- step - - while go2 do - yield e.Current - let! step = e.MoveNextAsync() - go2 <- step + if go then + while! e.MoveNextAsync() do + yield e.Current } return first.ToArray(), rest