I have a piece of code that is of the following form
let function arg1 arg2 =
match arg1 with
| type1 -> Some true
| type2 ->
async {
match! func2 arg3 arg4 with
| Result.Ok a -> return! Some true
| _ -> return! None
}
The problem here is that the func2 has to be used with match! statement and a normal match keyword is not able to compute the expression and thus I can not match pattern Some a. However, I can not use async in one of the branches alone.
Is there any method in F# that can convert Async<Result<a>> to Result<a> type ?
I am expecting a method such as Async.Evaluate that can perform computation and return a simple Result<a> object instead of a Async<Result<a>>. that would my code snippet look something like:
let function arg1 arg2 =
match arg1 with
| type1 -> Some true
| type2 ->
match (func2 arg3 arg4) |> Async.Evaluate with
| Result.Ok a -> Some true
| _ -> None