Search code examples
asynchronousf#seq

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!


Solution

  • 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
    }