CCOpt.get

This commit is contained in:
Simon Cruanes 2014-10-18 17:15:42 +02:00
parent 22343b4469
commit 1e07897da8
2 changed files with 8 additions and 0 deletions

View file

@ -92,6 +92,10 @@ let fold f acc o = match o with
| None -> acc
| Some x -> f acc x
let get default x = match x with
| None -> default
| Some y -> y
let get_exn = function
| Some x -> x
| None -> invalid_arg "CCOpt.get_exn"

View file

@ -60,6 +60,10 @@ val iter : ('a -> unit) -> 'a t -> unit
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** Fold on 0 or 1 elements *)
val get : 'a -> 'a t -> 'a
(** [get default x] unwraps [x], but if [x = None] it returns [default] instead.
@since NEXT_RELEASE *)
val get_exn : 'a t -> 'a
(** Open the option, possibly failing if it is [None]
@raise Invalid_argument if the option is [None] *)