add CCResult.get_lazy

This commit is contained in:
Simon Cruanes 2020-05-21 15:26:27 -04:00
parent d7a7cbb170
commit 5dd90edafa
2 changed files with 9 additions and 0 deletions

View file

@ -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

View file

@ -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].