diff --git a/src/core/CCOption.ml b/src/core/CCOption.ml index 0f982405..e6276a50 100644 --- a/src/core/CCOption.ml +++ b/src/core/CCOption.ml @@ -46,6 +46,11 @@ let[@inline] flat_map f o = | None -> None | Some x -> f x +let[@inline] flat_map_l f o = + match o with + | None -> [] + | Some x -> f x + let[@inline] bind o f = flat_map f o let ( >>= ) = bind let pure x = Some x diff --git a/src/core/CCOption.mli b/src/core/CCOption.mli index 781edf87..d305449b 100644 --- a/src/core/CCOption.mli +++ b/src/core/CCOption.mli @@ -49,6 +49,10 @@ val flat_map : ('a -> 'b t) -> 'a t -> 'b t (** [flat_map f o] is equivalent to {!map} followed by {!flatten}. Flip version of {!(>>=)}. *) +val flat_map_l : ('a -> 'b list) -> 'a t -> 'b list +(** [flat_map_l f o] is [[]] if [o] is [None], or [f x] if [o] is [Some x]. + @since NEXT_RELEASE *) + val bind : 'a t -> ('a -> 'b t) -> 'b t (** [bind o f] is [f v] if [o] is [Some v], [None] otherwise. Monadic bind.