mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 03:05:29 -05:00
printing functions
This commit is contained in:
parent
61a4f64e75
commit
b1e5176177
2 changed files with 20 additions and 0 deletions
13
sequence.ml
13
sequence.ml
|
|
@ -713,3 +713,16 @@ let pp_seq ?(sep=", ") pp_elt formatter seq =
|
|||
end);
|
||||
pp_elt formatter x)
|
||||
seq
|
||||
|
||||
let pp_buf ?(sep=", ") pp_elt buf seq =
|
||||
let first = ref true in
|
||||
iter
|
||||
(fun x ->
|
||||
if !first then first := false else Buffer.add_string buf sep;
|
||||
pp_elt buf x)
|
||||
seq
|
||||
|
||||
let to_string ?sep pp_elt seq =
|
||||
let buf = Buffer.create 25 in
|
||||
pp_buf ?sep (fun buf x -> Buffer.add_string buf (pp_elt x)) buf seq;
|
||||
Buffer.contents buf
|
||||
|
|
|
|||
|
|
@ -442,3 +442,10 @@ val pp_seq : ?sep:string -> (Format.formatter -> 'a -> unit) ->
|
|||
Format.formatter -> 'a t -> unit
|
||||
(** Pretty print a sequence of ['a], using the given pretty printer
|
||||
to print each elements. An optional separator string can be provided. *)
|
||||
|
||||
val pp_buf : ?sep:string -> (Buffer.t -> 'a -> unit) ->
|
||||
Buffer.t -> 'a t -> unit
|
||||
(** Print into a buffer *)
|
||||
|
||||
val to_string : ?sep:string -> ('a -> string) -> 'a t -> string
|
||||
(** Print into a string *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue