From f13fb6f47114f0b93313bc0fda83c8ec71849977 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 25 Nov 2025 19:59:23 -0500 Subject: [PATCH] feat pvec: add `flat_map` --- src/pvec/containers_pvec.ml | 3 +++ src/pvec/containers_pvec.mli | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/pvec/containers_pvec.ml b/src/pvec/containers_pvec.ml index 9f30dd07..6de797fe 100644 --- a/src/pvec/containers_pvec.ml +++ b/src/pvec/containers_pvec.ml @@ -352,6 +352,9 @@ let append a b = else fold_left push a b +let flat_map f v : _ t = + fold_left (fun acc x -> append acc (f x)) empty v + let rec equal_tree eq t1 t2 = match t1, t2 with | Empty, Empty -> true diff --git a/src/pvec/containers_pvec.mli b/src/pvec/containers_pvec.mli index 2112a4d0..2c3bd25e 100644 --- a/src/pvec/containers_pvec.mli +++ b/src/pvec/containers_pvec.mli @@ -82,8 +82,12 @@ val append : 'a t -> 'a t -> 'a t (** [append a b] adds all elements of [b] at the end of [a]. This is at least linear in the length of [b]. *) + val map : ('a -> 'b) -> 'a t -> 'b t +val flat_map : ('a -> 'b t) -> 'a t -> 'b t +(** @since NEXT_RELEASE *) + val choose : 'a t -> 'a option (** Return an element. It is unspecified which one is returned. *)