udpate doc and add test

This commit is contained in:
Simon Cruanes 2021-04-27 13:21:34 -04:00
parent 3628feed9c
commit c99f7818c3
2 changed files with 9 additions and 2 deletions

View file

@ -114,6 +114,11 @@ let get_exn_or msg = function
| Some x -> x
| None -> invalid_arg msg
(*$T
(try get_exn_or "ohno" (None:unit option); false with Invalid_argument s->s= "ohno")
123 = get_exn_or "yes" (Some 123)
*)
let get_lazy default_fn x = match x with
| None -> default_fn ()
| Some y -> y

View file

@ -95,8 +95,10 @@ val get_exn : 'a t -> 'a
*)
val get_exn_or : string -> 'a t -> 'a
(** [get_exn msg o] returns [x] if [o] is [Some x] or fails with [Invalid_argument msg] if [o] is [None].
@raise Invalid_argument if the option is [None]. *)
(** [get_exn_or msg o] returns [x] if [o] is [Some x]
or fails with [Invalid_argument msg] if [o] is [None].
@raise Invalid_argument if the option is [None].
@since NEXT_RELEASE *)
val get_lazy : (unit -> 'a) -> 'a t -> 'a
(** [get_lazy default_fn o] unwraps [o], but if [o] is [None] it returns [default_fn ()] instead.