I have a simple implementation for "Async.sequence
" (the name came from here), but I would like someone to review it for performance, tail call optimization, and functional style.
It has the following signature, which is similar to Async.Parallel
:
Async<'a> list -> Async<'a list>
Async.Parallel
would be ideal for performance, but it may be important to run the operations in order even though they happen to be async.
let sequence list =
let rec loop l acc =
async {
match l with
| [] ->
return List.rev acc
| h::t ->
let! h' = h
return! loop t (h'::acc)
}
loop list []