AsyncValidation Computation Expression
type AsyncValidation<'a,'err> = Async<Result<'a, 'err list>>
// Result<string, string> -> Async<Result<string, string>>
let downloadAsync stuff = async {
return stuff
}
// AsyncValidation<string, string>
let addResult = asyncValidation {
let! x = downloadAsync (Ok "I")
and! y = downloadAsync (Ok "am")
and! z = downloadAsync (Ok "async!")
return sprintf "%s %s %s" x y z
}
// async { return Ok "I am async!" }
// AsyncValidation<string, string>
let addResult = asyncValidation {
let! x = downloadAsync (Error "Am")
and! y = downloadAsync (Error "I")
and! z = downloadAsync (Error "async?")
return sprintf "%s %s %s" x y z
}
// async { return Error [ "Am"; "I"; "async?" ] }