diff --git a/src/core/CCResult.ml b/src/core/CCResult.ml index 57e48752..da374da6 100644 --- a/src/core/CCResult.ml +++ b/src/core/CCResult.ml @@ -245,6 +245,16 @@ let to_seq e k = match e with | Ok x -> k x | Error _ -> () +type ('a, 'b) error = [`Ok of 'a | `Error of 'b] + +let of_err = function + | `Ok x -> Ok x + | `Error y -> Error y + +let to_err = function + | Ok x -> `Ok x + | Error y -> `Error y + (** {2 IO} *) let pp pp_x buf e = match e with diff --git a/src/core/CCResult.mli b/src/core/CCResult.mli index 1a72e3a3..7a4a2c28 100644 --- a/src/core/CCResult.mli +++ b/src/core/CCResult.mli @@ -181,6 +181,14 @@ val of_opt : 'a option -> ('a, string) t val to_seq : ('a, _) t -> 'a sequence +type ('a, 'b) error = [`Ok of 'a | `Error of 'b] + +val of_err : ('a, 'b) error -> ('a, 'b) t +(** @since NEXT_RELEASE *) + +val to_err : ('a, 'b) t -> ('a, 'b) error +(** @since NEXT_RELEASE *) + (** {2 IO} *) val pp : 'a printer -> ('a, string) t printer