diff --git a/src/core/CCVector.ml b/src/core/CCVector.ml index 5180758e..acf8d8ca 100644 --- a/src/core/CCVector.ml +++ b/src/core/CCVector.ml @@ -533,15 +533,26 @@ let flat_map f v = iter (fun x -> iter (push v') (f x)) v; v' -let flat_map' f v = +let flat_map_seq f v = let v' = create () in iter (fun x -> let seq = f x in - seq (fun y -> push v' y) + append_seq v' seq; ) v; v' +let flat_map_list f v = + let v' = create () in + iter + (fun x -> + let l = f x in + append_list v' l; + ) v; + v' + +let flat_map' = flat_map_seq + let (>>=) x f = flat_map f x let (>|=) x f = map f x diff --git a/src/core/CCVector.mli b/src/core/CCVector.mli index 17d21bfd..deec25fd 100644 --- a/src/core/CCVector.mli +++ b/src/core/CCVector.mli @@ -190,8 +190,19 @@ val filter_map : ('a -> 'b option) -> ('a,_) t -> ('b, 'mut) t val flat_map : ('a -> ('b,_) t) -> ('a,_) t -> ('b, 'mut) t (** Map each element to a sub-vector *) +val flat_map_seq : ('a -> 'b sequence) -> ('a,_) t -> ('b, 'mut) t +(** Like {!flat_map}, but using {!sequence} for + intermediate collections. + @since NEXT_RELEASE *) + +val flat_map_list : ('a -> 'b list) -> ('a,_) t -> ('b, 'mut) t +(** Like {!flat_map}, but using {!list} for + intermediate collections. + @since NEXT_RELEASE *) + val flat_map' : ('a -> 'b sequence) -> ('a,_) t -> ('b, 'mut) t -(** Like {!flat_map}, but using {!sequence} for intermediate collections *) +(** Alias to {!flat_map_seq} + @deprecated since NEXT_RELEASE , use {!flat_map_seq} *) val (>>=) : ('a,_) t -> ('a -> ('b,_) t) -> ('b, 'mut) t (** Infix version of {!flat_map} *)