Skip to content

Instantly share code, notes, and snippets.

@dam5s
Last active January 23, 2019 01:54
Show Gist options
  • Save dam5s/392851fdc1a905af5191d48978bd856a to your computer and use it in GitHub Desktop.
Save dam5s/392851fdc1a905af5191d48978bd856a to your computer and use it in GitHub Desktop.
[<AutoOpen>]
module Prelude
type AsyncResult<'T, 'TError> =
Async<Result<'T, 'TError>>
module AsyncResult =
let map (mapping : 'T -> 'U) (result : AsyncResult<'T, 'TError>) : AsyncResult<'U, 'TError> =
async {
match! result with
| Ok value -> return Ok (mapping value)
| Error err -> return Error err
}
let bind (mapping : 'T -> AsyncResult<'U, 'TError>) (result : AsyncResult<'T, 'TError>) : AsyncResult<'U, 'TError> =
async {
match! result with
| Ok value -> return! mapping value
| Error err -> return Error err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment