From 55a4c7ef7a8604b91d184792adbdf99da5a80e89 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 11 Apr 2016 20:56:39 +0200 Subject: [PATCH] add `Result.{to,of}_err` --- src/core/CCResult.ml | 10 ++++++++++ src/core/CCResult.mli | 8 ++++++++ 2 files changed, 18 insertions(+) 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