Closed TheAngryByrd closed 5 years ago
I was wanting some adapter functions that lived in the AsyncResult space. I shoehorned these into one of the projects I'm currently working on.
// ('a -> Result<'b,'c>) -> ('a -> AsyncResult<'b,'c>) let resultToAsync (f : 'a -> Result<'b,'c>) x = x |> f |> Async.singleton |> AR // ('a -> 'b) -> (AsyncResult<'a,'c> -> AsyncResult<'b,'c>) let liftAsyncResult (oneTrackFunction : 'a -> 'b) (twoTrackInput : AsyncResult<'a,'c>) = asyncTrial { let! twoTrackResult = twoTrackInput return oneTrackFunction twoTrackResult } // ('a -> AsyncResult<'b,'c>) -> (AsyncResult<'a,'c> -> AsyncResult<'b,'c>) let bindAsyncResult (switchFunction : 'a -> AsyncResult<'b,'c>) (twoTrackInput : AsyncResult<'a,'c>)= asyncTrial { let! twoTrackResult = twoTrackInput return! switchFunction twoTrackResult }
The use case I had in mind was:
let updateSomeRecord = resultToAsync validate >> bindAsyncResult queryDatabase >> liftAsyncResult saveResults >> Async.ofAsyncResult
Probably not the best implementation and names need to change. Should I make a PR for this?
I was wanting some adapter functions that lived in the AsyncResult space. I shoehorned these into one of the projects I'm currently working on.
The use case I had in mind was:
Probably not the best implementation and names need to change. Should I make a PR for this?