question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatability with AsyncSeq?

See original GitHub issue

So FSharp.Control.AsyncSeq extends async so that you can do this:

async {
  let xs = asyncSeq {
    yield 1
    yield 2 
    yield 3
  }

  for x in xs do
    printfn "%A" x
}

But this is not implemented for asyncResult:

async {
  let xs = asyncSeq {
    yield 1
    yield 2 
    yield 3
  }

  for x in xs do // Only seq allowed here
    printfn "%A" x
}

I would be great if this worked, although I’m not sure how it could be implemented. Perhaps this is just a limitation of F#?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
njlrcommented, May 11, 2020

I was able to design an async version like this:

[<AutoOpen>]
module AsyncSeqExtensions =

  // Add asynchronous for loop to the 'asyncResult' computation builder
  type FsToolkit.ErrorHandling.AsyncResultCE.AsyncResultBuilder
    with
      member x.For (seq : AsyncSeq<Result<'T, 'TError>>, action : 'T -> Async<Result<unit, 'TError>>) : Async<Result<unit, 'TError>> =
        seq
        |> AsyncSeq.foldAsync
          (fun acc x ->
            async {
              match acc, x with
              | Ok (), Ok x ->
                return! action x
              | Ok (), Error e ->
                return Error e
              | acc, _ ->
                return acc
            })
          (Ok ())

I’m still unsure of the best semantics though…

  • Should the for stop at the first Result.Error?
  • Should only AsyncSeq<Result<_, _>> be supported?
0reactions
njlrcommented, Sep 13, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

FSharp.Control.AsyncSeq
FSharp.Control.AsyncSeq is a collection of asynchronous programming utilities for F#. An AsyncSeq is a sequence in which individual elements are retrieved using ...
Read more >
FSharp.Control.AsyncSeq 3.2.1
Asynchronous sequences for F#.
Read more >
fsprojects/FSharp.Control.AsyncSeq
FSharp.Control.AsyncSeq is a collection of asynchronous programming utilities for F#. See the home page for details. The home page can be edited, forked...
Read more >
Programming with F# asynchronous sequences
The asyncSeq { .. } block iterates over a (synchronous) list of URLs using a for loop. The body of the loop is...
Read more >
Unordered F# AsyncSeq.mapParallel with throttling
Hmm. I'm not an async expert, but I don't think that AsyncSeq.fold works like that. If the first call in the sequence takes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found