From 1ed81107df65341a4f59c457ee72261b948b9ec3 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 1 Apr 2023 20:07:59 -0400 Subject: [PATCH] pp: expose fill and and fill_map --- src/pp/containers_pp.ml | 2 ++ src/pp/containers_pp.mli | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/pp/containers_pp.ml b/src/pp/containers_pp.ml index 1543a4c7..6a6f41f1 100644 --- a/src/pp/containers_pp.ml +++ b/src/pp/containers_pp.ml @@ -358,6 +358,8 @@ let fill sep = function in { view = Fill { sep; l }; wfl } +let fill_map sep f l = fill sep (List.map f l) + let of_list ?(sep = nil) f l = let rec loop = function | [] -> nil diff --git a/src/pp/containers_pp.mli b/src/pp/containers_pp.mli index 1726b0bb..06edd052 100644 --- a/src/pp/containers_pp.mli +++ b/src/pp/containers_pp.mli @@ -55,6 +55,12 @@ val newline : t val nl : t (** Alias for {!newline} *) +val fill : t -> t list -> t +(** [fill sep l] resembles [group (append_l ~sep l)], except it tries + to put as many items of [l] as possible on each line. + + In terms of {!Format}, this is like the hov box. *) + (** {2 Output device} *) (** Arbitrary output. @@ -167,6 +173,9 @@ val append_sp : t list -> t val append_nl : t list -> t (** Same as {!append_l} with [sep=nl] *) +val fill_map : t -> ('a -> t) -> 'a list -> t +(** [fill_map sep f l] is [fill sep (List.map f l)] *) + val bool : bool -> t val int : int -> t val float : float -> t