feat pvec: add flat_map

This commit is contained in:
Simon Cruanes 2025-11-25 19:59:23 -05:00
parent 01402388e4
commit f13fb6f471
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 7 additions and 0 deletions

View file

@ -352,6 +352,9 @@ let append a b =
else else
fold_left push a b 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 = let rec equal_tree eq t1 t2 =
match t1, t2 with match t1, t2 with
| Empty, Empty -> true | Empty, Empty -> true

View file

@ -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 (** [append a b] adds all elements of [b] at the end of [a]. This is
at least linear in the length of [b]. *) at least linear in the length of [b]. *)
val map : ('a -> 'b) -> 'a t -> 'b t 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 val choose : 'a t -> 'a option
(** Return an element. It is unspecified which one is returned. *) (** Return an element. It is unspecified which one is returned. *)