fsprojects / FSharp.Control.TaskSeq

A computation expression and module for seamless working with IAsyncEnumerable<'T> as if it is just another sequence
MIT License
93 stars 8 forks source link

Bug: `TaskSeq.item` and `tryItem` should NOT read past the found item, not even a little bit #65

Closed abelbraaksma closed 2 years ago

abelbraaksma commented 2 years ago

Consider this:

task {
    let mutable i = 0

    let ts = taskSeq {
        i <- i + 1
        yield 1
        i <- i + 1
        yield 2
        i <- i + 1 // we should never get here, if we pick idx 1
    }

    do! ts |> TaskSeq.item 1
    printfn "%i" i
}

This prints "3", not "2". That's wrong. Side effects beyond the item found should not execute.

abelbraaksma commented 2 years ago

Test added in #61.