diff --git a/core/CCError.ml b/core/CCError.ml index 8418f21f..da7f7888 100644 --- a/core/CCError.ml +++ b/core/CCError.ml @@ -49,6 +49,10 @@ let map f e = match e with | `Ok x -> `Ok (f x) | `Error s -> `Error s +let map2 f g e = match e with + | `Ok x -> `Ok (f x) + | `Error s -> `Error (g s) + let flat_map f e = match e with | `Ok x -> f x | `Error s -> `Error s diff --git a/core/CCError.mli b/core/CCError.mli index 49462101..61e8e98a 100644 --- a/core/CCError.mli +++ b/core/CCError.mli @@ -47,6 +47,10 @@ val of_exn : exn -> 'a t val map : ('a -> 'b) -> 'a t -> 'b t +val map2 : ('a -> 'b) -> (string -> string) -> 'a t -> 'b t +(** Same as {!map}, but also with a function that can transform + the error message in case of failure *) + val flat_map : ('a -> 'b t) -> 'a t -> 'b t val guard : (unit -> 'a) -> 'a t