Merge pull request #10 from Drup/master

Add CCOpt.filter.
This commit is contained in:
Simon Cruanes 2014-11-07 09:48:08 +01:00
commit 0fd2a28693
2 changed files with 9 additions and 0 deletions

View file

@ -84,6 +84,10 @@ let map2 f o1 o2 = match o1, o2 with
| _, None -> None
| Some x, Some y -> Some (f x y)
let filter p = function
| Some x as o when p x -> o
| o -> o
let iter f o = match o with
| None -> ()
| Some x -> f x

View file

@ -60,6 +60,11 @@ val iter : ('a -> unit) -> 'a t -> unit
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** Fold on 0 or 1 elements *)
val filter : ('a -> bool) -> 'a t -> 'a t
(** Filter on 0 or 1 elements
@since NEXT_RELEASE *)
val get : 'a -> 'a t -> 'a
(** [get default x] unwraps [x], but if [x = None] it returns [default] instead.
@since NEXT_RELEASE *)