mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
pretty printing of an Enum
This commit is contained in:
parent
bd99d044f7
commit
64a50fbedf
2 changed files with 23 additions and 0 deletions
19
enum.ml
19
enum.ml
|
|
@ -492,6 +492,25 @@ let int_range i j =
|
|||
x
|
||||
end
|
||||
|
||||
let pp ?(start="") ?(stop="") ?(sep=",") ?(horizontal=false) pp_elem formatter enum =
|
||||
(if horizontal
|
||||
then Format.fprintf formatter "@[<h>%s" start
|
||||
else Format.fprintf formatter "@[%s" start);
|
||||
let gen = enum () in
|
||||
let rec next is_first =
|
||||
let continue_ =
|
||||
try
|
||||
let x = gen () in
|
||||
(if not is_first
|
||||
then Format.fprintf formatter "%s@,%a" sep pp_elem x
|
||||
else pp_elem formatter x);
|
||||
true
|
||||
with EOG -> false in
|
||||
if continue_ then next false
|
||||
in
|
||||
next true;
|
||||
Format.fprintf formatter "%s@]" stop
|
||||
|
||||
module Infix = struct
|
||||
let (@@) = append
|
||||
|
||||
|
|
|
|||
4
enum.mli
4
enum.mli
|
|
@ -182,6 +182,10 @@ val to_rev_list : 'a t -> 'a list
|
|||
|
||||
val int_range : int -> int -> int t
|
||||
|
||||
val pp : ?start:string -> ?stop:string -> ?sep:string -> ?horizontal:bool ->
|
||||
(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
|
||||
(** Pretty print an enum *)
|
||||
|
||||
module Infix : sig
|
||||
val (@@) : 'a t -> 'a t -> 'a t
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue