Tom Soyer
Tom Soyer

Reputation: 53

type 'Async<string []>' is not compatible with the type 'seq<'a>'

I have a mySources variable, seq<Async <string []>>. My aim is to flatten the sequence and join all elements in a sequence, in a single Async<string []>

I am using Seq.collect method.

let myJoinedAsyncs = Seq.collect (fun elems -> elems) mySources

But this line gives me an error on mySource indicating that:

the type 'Async' is not compatible with the type 'seq<'a>'

Any ideas? Thanks!

Upvotes: 5

Views: 194

Answers (1)

Lee
Lee

Reputation: 144136

You can use Async.Parallel to collect the inner values and concat the resulting sequences:

let flattenAsync (asyncs : seq<Async<'a []>>) = async {
    let! ss = Async.Parallel asyncs
    return Array.concat ss
}

Upvotes: 5

Related Questions