I am attempting to get to grips with Railway Oriented Programming using Chessie.
I have several API libraries written in C# whichI am shimming to provide a safer interface - rather than Task I would like to provide Async<Result<foo,_>.
With this in mind, I am struggling to see how I get an Async or Async<Result<foo,>> into an AsyncResult<foo,>>
I am new to the language, and assume I am missing something.
Thanks
Jono
I ended up with
asyncTrial {
return! AR(
async {
// normal async code here.
}
)
}
A very late reply, but just in case someone else stumbles across this:
open System
open Chessie
open Chessie.ErrorHandling
[<EntryPoint>]
let main argv =
let maybeFoo (aBool: bool) =
async{
if aBool
then return ok (true,["it was true"])
else return fail "failed"
}
let resultFoo : AsyncResult<_,_> =
AR (maybeFoo true)
0
It’s a single case discriminated union, so it just needs wrapping. The source:
/// Represents the result of an async computation
[<NoComparison;NoEquality>]
type AsyncResult<'a, 'b> =
| AR of Async<Result<'a, 'b>>