Like List.sequenceAsyncResultM but would stop at the first success.
Is there something like this already provided?
let firstSuccess (tasks : Async<Result<'ok, 'error>> list) : Async<Result<'ok, 'error list>> =
let rec loop (errors : 'e list) tasks =
async {
match tasks with
| [] ->
return Error (List.rev errors)
| x :: xs ->
match! x with
| Ok t ->
return Ok t
| Error error ->
return! loop (error :: errors) xs
}
loop [] tasks
If not, would a PR be accepted?
Thanks!