Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 740
Tom Soyer Avatar asked Dec 09 '16 17:12

Tom Soyer


1 Answers

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
}
like image 110
Lee Avatar answered Oct 06 '22 00:10

Lee