Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix TaskSeq.truncate reading one too many from the input
  • Loading branch information
abelbraaksma committed Dec 19, 2023
commit 140f82b39cf016f6dd7668ee182af7721f56e0db
10 changes: 6 additions & 4 deletions src/FSharp.Control.TaskSeq/TaskSeqInternal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module internal TaskSeqInternal =
let inline raiseCannotBeNegative name = invalidArg name "The value must be non-negative"

let inline raiseInsufficient () =
// this is correct, it is NOT an InvalidOperationException (see Seq.fs in F# Core)
// but instead, it's an ArgumentException... FWIW lol
invalidArg "source" "The input task sequence was has an insufficient number of elements."

let inline raiseNotFound () =
Expand Down Expand Up @@ -136,15 +138,15 @@ module internal TaskSeqInternal =
i <- i + 1 // update before moving: we are counting, not indexing
go <- step

| Some(Predicate predicate) ->
| Some (Predicate predicate) ->
while go do
if predicate e.Current then
i <- i + 1

let! step = e.MoveNextAsync()
go <- step

| Some(PredicateAsync predicate) ->
| Some (PredicateAsync predicate) ->
while go do
match! predicate e.Current with
| true -> i <- i + 1
Expand Down Expand Up @@ -213,7 +215,7 @@ module internal TaskSeqInternal =
// multiple threads access the same item through the same enumerator (which is
// bad practice, but hey, who're we to judge).
if isNull value then
value <- Lazy<_>.Create(fun () -> init i)
value <- Lazy<_>.Create (fun () -> init i)

yield value.Force()
value <- Unchecked.defaultof<_>
Expand Down Expand Up @@ -720,7 +722,7 @@ module internal TaskSeqInternal =
yield e.Current
pos <- pos + 1
let! moveNext = e.MoveNextAsync()
cont <- moveNext && pos <= count
cont <- moveNext && pos < count

}

Expand Down