mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add CCFormat.within
This commit is contained in:
parent
55c9d6c60b
commit
a9b91943e8
2 changed files with 23 additions and 9 deletions
|
|
@ -76,14 +76,19 @@ let opt pp fmt x = match x with
|
|||
| None -> Format.pp_print_string fmt "none"
|
||||
| Some x -> Format.fprintf fmt "some %a" pp x
|
||||
|
||||
let pair ppa ppb fmt (a, b) =
|
||||
Format.fprintf fmt "(%a,@ %a)" ppa a ppb b
|
||||
let pair ?(sep=", ") ppa ppb fmt (a, b) =
|
||||
Format.fprintf fmt "(%a%s@,%a)" ppa a sep ppb b
|
||||
|
||||
let triple ppa ppb ppc fmt (a, b, c) =
|
||||
Format.fprintf fmt "(%a,@ %a,@ %a)" ppa a ppb b ppc c
|
||||
let triple ?(sep=", ") ppa ppb ppc fmt (a, b, c) =
|
||||
Format.fprintf fmt "(%a%s@,%a%s@,%a)" ppa a sep ppb b sep ppc c
|
||||
|
||||
let quad ppa ppb ppc ppd fmt (a, b, c, d) =
|
||||
Format.fprintf fmt "(%a,@ %a,@ %a,@ %a)" ppa a ppb b ppc c ppd d
|
||||
let quad ?(sep=", ") ppa ppb ppc ppd fmt (a, b, c, d) =
|
||||
Format.fprintf fmt "(%a%s@,%a%s@,%a%s@,%a)" ppa a sep ppb b sep ppc c sep ppd d
|
||||
|
||||
let within a b p out x =
|
||||
string out a;
|
||||
p out x;
|
||||
string out b
|
||||
|
||||
let map f pp fmt x =
|
||||
pp fmt (f x);
|
||||
|
|
|
|||
|
|
@ -38,9 +38,18 @@ val seq : ?start:string -> ?stop:string -> ?sep:string -> 'a printer -> 'a seque
|
|||
|
||||
val opt : 'a printer -> 'a option printer
|
||||
|
||||
val pair : 'a printer -> 'b printer -> ('a * 'b) printer
|
||||
val triple : 'a printer -> 'b printer -> 'c printer -> ('a * 'b * 'c) printer
|
||||
val quad : 'a printer -> 'b printer -> 'c printer -> 'd printer -> ('a * 'b * 'c * 'd) printer
|
||||
(** In the tuple printers, the [sep] argument is only available
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val pair : ?sep:string -> 'a printer -> 'b printer -> ('a * 'b) printer
|
||||
val triple : ?sep:string -> 'a printer -> 'b printer -> 'c printer -> ('a * 'b * 'c) printer
|
||||
val quad : ?sep:string -> 'a printer -> 'b printer ->
|
||||
'c printer -> 'd printer -> ('a * 'b * 'c * 'd) printer
|
||||
|
||||
val within : string -> string -> 'a printer -> 'a printer
|
||||
(** [within a b p] wraps [p] inside the strings [a] and [b]. Convenient,
|
||||
for instances, for brackets, parenthesis, quotes, etc.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val map : ('a -> 'b) -> 'b printer -> 'a printer
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue