From 5cdf59f30c3cb9edd07c346a8d895cc5d76c54cb Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 24 Feb 2016 20:37:56 +0100 Subject: [PATCH] add `CCOpt.map_or`, deprecating `CCopt.maybe` --- src/core/CCOpt.ml | 6 ++++-- src/core/CCOpt.mli | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index fa2b7b30..4427e332 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -9,10 +9,12 @@ let map f = function | None -> None | Some x -> Some (f x) -let maybe f d = function - | None -> d +let map_or ~default f = function + | None -> default | Some x -> f x +let maybe f default = map_or ~default f + let is_some = function | None -> false | Some _ -> true diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index 64d1c7f9..f14ca823 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -9,7 +9,13 @@ val map : ('a -> 'b) -> 'a t -> 'b t (** Transform the element inside, if any *) 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