diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index 9c9d0146..c6f5ea8c 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -4,10 +4,6 @@ type 'a t = 'a option -let bind f = function - | None -> None - | Some x -> f x - let map f = function | None -> None | Some x -> Some (f x) @@ -42,14 +38,14 @@ let equal f o1 o2 = match o1, o2 with let return x = Some x -let (>>=) o f = match o with - | None -> None - | Some x -> f x - let flat_map f o = match o with | None -> None | Some x -> f x +let bind o f = flat_map f o + +let (>>=) = bind + let pure x = Some x let (<*>) f x = match f, x with diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index bd91f703..5b806c54 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -4,10 +4,6 @@ type +'a t = 'a option -val bind : ('a -> 'b t) -> 'a t -> 'b t -(** [bind f o] if [o] is [Some v] then [f v] else [None] - @since NEXT_RELEASE *) - val map : ('a -> 'b) -> 'a t -> 'b t (** Transform the element inside, if any. *) @@ -39,12 +35,17 @@ val return : 'a -> 'a t val (>|=) : 'a t -> ('a -> 'b) -> 'b t (** Infix version of {!map}. *) -val (>>=) : 'a t -> ('a -> 'b t) -> 'b t -(** Monadic bind. *) - val flat_map : ('a -> 'b t) -> 'a t -> 'b t (** Flip version of {!>>=}. *) +val bind : 'a t -> ('a -> 'b t) -> 'b t +(** Monadic bind. + [bind f o] if [o] is [Some v] then [f v] else [None] + @since NEXT_RELEASE *) + +val (>>=) : 'a t -> ('a -> 'b t) -> 'b t +(** Infix version of {!bind}. *) + val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t (** [map2 f o1 o2] maps ['a option] and ['b option] to a ['c option] using [f]. *)