mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
add CCResult.get_lazy
This commit is contained in:
parent
d7a7cbb170
commit
5dd90edafa
2 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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].
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue