Last active
August 29, 2015 14:23
-
-
Save hcarty/a1766866cb29d885c43b to your computer and use it in GitHub Desktop.
A small amount of Rresult + Lwt, somewhat in the style of Pvem's Lwt support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Rresult | |
include R | |
type ('a, 'b) result_lwt = ('a, 'b) result Lwt.t | |
let ok x = Lwt.return @@ Ok x | |
let error e = Lwt.return @@ Error e | |
let return = ok | |
let bind x f = | |
Lwt.bind x ( | |
function | |
| Error _ as e -> Lwt.return e | |
| Ok o -> f o | |
) | |
let ( >>= ) = bind | |
let map m f = | |
m >>= fun x -> return (f x) | |
let ( >>| ) = map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Rresult | |
include module type of R | |
type ('a, 'b) result_lwt = ('a, 'b) result Lwt.t | |
val ok : 'a -> ('a, 'b) result_lwt | |
val error : 'b -> ('a, 'b) result_lwt | |
val return : 'a -> ('a, 'b) result_lwt | |
val bind : | |
('a, 'b) result_lwt -> ('a -> ('c, 'b) result_lwt) -> ('c, 'b) result_lwt | |
val ( >>= ) : | |
('a, 'b) result_lwt -> ('a -> ('c, 'b) result_lwt) -> ('c, 'b) result_lwt | |
(** aka {!bind} *) | |
val map : ('a, 'b) result_lwt -> ('a -> 'c) -> ('c, 'b) result_lwt | |
val ( >>| ) : ('a, 'b) result_lwt -> ('a -> 'c) -> ('c, 'b) result_lwt | |
(** aka {!map} *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment