diff --git a/src/core/CCResult.ml b/src/core/CCResult.ml index 50d02716..40439c50 100644 --- a/src/core/CCResult.ml +++ b/src/core/CCResult.ml @@ -107,6 +107,10 @@ let get_or e ~default = match e with | Ok x -> x | Error _ -> default +let get_lazy f e = match e with + | Ok x -> x + | Error e -> f e + let get_or_failwith = function | Ok x -> x | Error msg -> failwith msg diff --git a/src/core/CCResult.mli b/src/core/CCResult.mli index 0201f263..9da387be 100644 --- a/src/core/CCResult.mli +++ b/src/core/CCResult.mli @@ -91,6 +91,11 @@ val get_exn : ('a, _) t -> 'a val get_or : ('a, _) t -> default:'a -> 'a (** [get_or e ~default] returns [x] if [e = Ok x], [default] otherwise. *) +val get_lazy : ('e -> 'a) -> ('a, 'e) t -> 'a +(** [get_lazy f e] returns [x] if [e = Ok x], [f msg] if [e = Error msg]. + This is similar to {!CCOpt.get_lazy}. + @since NEXT_RELEASE *) + val get_or_failwith : ('a, string) t -> 'a (** [get_or_failwith e] returns [x] if [e = Ok x], fails otherwise. @raise Failure with [msg] if [e = Error msg].