add CCOpt.{for_all, exists}

This commit is contained in:
Simon Cruanes 2016-04-18 13:19:26 +02:00
parent 037f169044
commit dba88f5302
2 changed files with 14 additions and 0 deletions

View file

@ -71,6 +71,14 @@ let filter p = function
| Some x as o when p x -> o
| o -> o
let exists p = function
| None -> false
| Some x -> p x
let for_all p = function
| None -> true
| Some x -> p x
let iter f o = match o with
| None -> ()
| Some x -> f x

View file

@ -50,6 +50,12 @@ val filter : ('a -> bool) -> 'a t -> 'a t
(** Filter on 0 or 1 element
@since 0.5 *)
val exists : ('a -> bool) -> 'a t -> bool
(** @since NEXT_RELEASE *)
val for_all : ('a -> bool) -> 'a t -> bool
(** @since NEXT_RELEASE *)
val get : 'a -> 'a t -> 'a
(** [get default x] unwraps [x], but if [x = None] it returns [default] instead.
@since 0.4.1 *)