add CCOpt.map_or, deprecating CCopt.maybe

This commit is contained in:
Simon Cruanes 2016-02-24 20:37:56 +01:00
parent 33b61e8bab
commit 5cdf59f30c
2 changed files with 11 additions and 3 deletions

View file

@ -9,10 +9,12 @@ let map f = function
| None -> None | None -> None
| Some x -> Some (f x) | Some x -> Some (f x)
let maybe f d = function let map_or ~default f = function
| None -> d | None -> default
| Some x -> f x | Some x -> f x
let maybe f default = map_or ~default f
let is_some = function let is_some = function
| None -> false | None -> false
| Some _ -> true | Some _ -> true

View file

@ -9,7 +9,13 @@ val map : ('a -> 'b) -> 'a t -> 'b t
(** Transform the element inside, if any *) (** Transform the element inside, if any *)
val maybe : ('a -> 'b) -> 'b -> 'a t -> 'b val maybe : ('a -> 'b) -> 'b -> 'a t -> 'b
(** [maybe f x o] is [x] if [o] is [None], otherwise it's [f y] if [o = Some y] *) (** [maybe f x o] is [x] if [o] is [None],
otherwise it's [f y] if [o = Some y]
@deprecated, use {!map_or} *)
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b
(** [map_or ~default f o] is [f x] if [o = Some x], [default otherwise]
@since NEXT_RELEASE *)
val is_some : _ t -> bool val is_some : _ t -> bool