From bf8db5dcffb4be52ae61a332abfb4db958a6339c Mon Sep 17 00:00:00 2001 From: Fardale Date: Mon, 6 Jan 2020 16:15:52 +0100 Subject: [PATCH] feat(opt): add bind --- src/core/CCOpt.ml | 4 ++++ src/core/CCOpt.mli | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index dbd8e70c..9c9d0146 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -4,6 +4,10 @@ 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) diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index 9d8c0145..bd91f703 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -4,6 +4,10 @@ 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. *)