@@ -300,8 +300,7 @@ module SideEffects =
300300
301301 [<Theory; ClassData( typeof< TestSideEffectTaskSeq>) >]
302302 let ``TaskSeq - lengthOrMax returns max and stops evaluation when sequence exceeds max`` variant = task {
303- // source has 10 items; max=5 → should stop early
304- // NOTE: the implementation reads one element ahead (N+1 total MoveNextAsync calls for result N)
303+ // source has 10 items; max=5 → should stop early after exactly 5 elements
305304 let mutable evaluated = 0
306305
307306 let ts = taskSeq {
@@ -312,14 +311,12 @@ module SideEffects =
312311
313312 let! len = ts |> TaskSeq.lengthOrMax 5
314313 len |> should equal 5
315- // exactly max+1 elements are pulled from the source due to read-ahead
316- evaluated |> should equal 6
314+ // exactly max elements are pulled from the source
315+ evaluated |> should equal 5
317316 }
318317
319318 [<Fact>]
320- let ``TaskSeq - lengthOrMax stops evaluating source after reaching max - read - ahead characteristic`` () = task {
321- // NOTE: the implementation calls MoveNextAsync once before the while loop,
322- // then once more per iteration. For max=N and a longer source, this means N+1 calls total.
319+ let ``TaskSeq - lengthOrMax stops evaluating source after reaching max`` () = task {
323320 let mutable sideEffects = 0
324321
325322 let ts = taskSeq {
@@ -330,14 +327,12 @@ module SideEffects =
330327
331328 let! len = ts |> TaskSeq.lengthOrMax 7
332329 len |> should equal 7
333- // max+1 elements are evaluated due to the read-ahead implementation pattern
334- sideEffects |> should equal 8
330+ // exactly max elements are evaluated
331+ sideEffects |> should equal 7
335332 }
336333
337334 [<Fact>]
338- let ``TaskSeq - lengthOrMax with max = 0 still evaluates the first element due to read- ahead`` () = task {
339- // The implementation unconditionally calls MoveNextAsync once before entering
340- // the while loop, so even max=0 evaluates the first element of the source.
335+ let ``TaskSeq - lengthOrMax with max = 0 evaluates zero elements`` () = task {
341336 let mutable sideEffects = 0
342337
343338 let ts = taskSeq {
@@ -349,6 +344,6 @@ module SideEffects =
349344
350345 let! len = ts |> TaskSeq.lengthOrMax 0
351346 len |> should equal 0
352- // one element was evaluated despite max=0
353- sideEffects |> should equal 1
347+ // no elements evaluated when max=0
348+ sideEffects |> should equal 0
354349 }
0 commit comments