Computation Expression
AsyncValidation Computation Expression
Namespace: FsToolkit.ErrorHandling
The AsyncValidation
type is defined as:
type AsyncValidation<'a,'err> = Async<Result<'a, 'err list>>
This CE can take advantage of the and! operator to join multiple error results into a list.
Examples
See here for other validation-like examples
// 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?" ] }
Last updated