From 13888edb4d0cadbc393ba96db6fc1e7b2c289e63 Mon Sep 17 00:00:00 2001 From: orbitz Date: Tue, 17 Jan 2017 07:45:47 +0100 Subject: [PATCH] Add is_ok and is_error, simple predicates for testing a result. This is useful for tests or asserts --- AUTHORS.adoc | 1 + src/core/CCResult.ml | 8 ++++++++ src/core/CCResult.mli | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/AUTHORS.adoc b/AUTHORS.adoc index de89cd30..f2be0ad2 100644 --- a/AUTHORS.adoc +++ b/AUTHORS.adoc @@ -16,3 +16,4 @@ - Johannes Kloos - Geoff Gole (@gsg) - Roma Sokolov (@little-arhat) +- Malcolm Matalka (`orbitz`) diff --git a/src/core/CCResult.ml b/src/core/CCResult.ml index 581d2d06..42b5c12d 100644 --- a/src/core/CCResult.ml +++ b/src/core/CCResult.ml @@ -98,6 +98,14 @@ let fold ~ok ~error x = match x with | Ok x -> ok x | Error s -> error s +let is_ok = function + | Ok _ -> true + | Error _ -> false + +let is_error = function + | Ok _ -> false + | Error _ -> true + (** {2 Wrappers} *) let guard f = diff --git a/src/core/CCResult.mli b/src/core/CCResult.mli index 49674995..3f0d73a3 100644 --- a/src/core/CCResult.mli +++ b/src/core/CCResult.mli @@ -87,6 +87,16 @@ val fold : ok:('a -> 'b) -> error:('err -> 'b) -> ('a, 'err) t -> 'b (** [fold ~ok ~error e] opens [e] and, if [e = Ok x], returns [ok x], otherwise [e = Error s] and it returns [error s]. *) +val is_ok : ('a, 'err) t -> bool +(** Return true if Ok/ + + @since NEXT_RELEASE *) + +val is_error : ('a, 'err) t -> bool +(** Return true if Error + + @since NEXT_RELEASE *) + (** {2 Wrappers} *) val guard : (unit -> 'a) -> ('a, exn) t