From 4c408d1182e11571bc9459fc08a4358ec4026831 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 26 Jun 2014 15:37:07 +0200 Subject: [PATCH] CCOpt.get_exn --- core/CCOpt.ml | 4 ++++ core/CCOpt.mli | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/CCOpt.ml b/core/CCOpt.ml index aca8cb5a..6ed63e5f 100644 --- a/core/CCOpt.ml +++ b/core/CCOpt.ml @@ -90,6 +90,10 @@ let fold f acc o = match o with | None -> acc | Some x -> f acc x +let get_exn = function + | Some x -> x + | None -> invalid_arg "CCOpt.get_exn" + let sequence_l l = let rec aux acc l = match l with | [] -> Some (List.rev acc) diff --git a/core/CCOpt.mli b/core/CCOpt.mli index bcf8a034..a8d60d6e 100644 --- a/core/CCOpt.mli +++ b/core/CCOpt.mli @@ -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_exn : 'a t -> 'a +(** Open the option, possibly failing if it is [None] + @raise Invalid_argument if the option is [None] *) + val sequence_l : 'a t list -> 'a list t (** {2 Applicative} *)