add CCOpt.if_

This commit is contained in:
Simon Cruanes 2016-04-19 11:49:12 +02:00
parent 777796d8a6
commit 07d11c4104
2 changed files with 6 additions and 0 deletions

View file

@ -71,6 +71,8 @@ let filter p = function
| Some x as o when p x -> o
| o -> o
let if_ p x = if p x then Some x else None
let exists p = function
| None -> false
| Some x -> p x

View file

@ -50,6 +50,10 @@ val filter : ('a -> bool) -> 'a t -> 'a t
(** Filter on 0 or 1 element
@since 0.5 *)
val if_ : ('a -> bool) -> 'a -> 'a option
(** [if_ f x] is [Some x] if [f x], [None] otherwise
@since NEXT_RELEASE *)
val exists : ('a -> bool) -> 'a t -> bool
(** @since NEXT_RELEASE *)