FSharp.Control.AsyncSeq icon indicating copy to clipboard operation
FSharp.Control.AsyncSeq copied to clipboard

Add YieldFrom overload for seq<'a>?

Open voroninp opened this issue 5 years ago • 1 comments

I'd like to turn Async<seq> to AsyncSeq

While this works

asyncSeq {
    for item in items -> item
}

yield! version does not:

asyncSeq {
    yield! items
}

I need this to get all pages from the endpoint in one go. Reading a single page yields Async<seq<Result>> , I'd like the result to be presented as AsyncSeq

voroninp avatar Nov 19 '20 07:11 voroninp

Both your solutions work the same way here. If yield! were implemented (not sure it has, since then), it would act the same as your first solution here. After all, sequences are delay-iterated.

If you want the whole result at once, then AsyncSeq is probably not the correct solution. Though, if you already have an Async<seq>, and you want to read all at once, you can just do Async.map Seq.toList.

If you do want AsyncSeq, it'll give you different behavior than you describe, but the solution in your first suggestion above does give you what you want.

For posterity, since a few days, taskSeq was released. In there, you can do taskSeq { yield! items }.

abelbraaksma avatar Nov 13 '22 00:11 abelbraaksma