mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-03-07 21:27:55 -05:00
CCFormat(fix): restaure the behaviour of CCFormat.opt
This commit is contained in:
parent
8f30ce25b6
commit
35803e586c
2 changed files with 11 additions and 4 deletions
|
|
@ -32,7 +32,6 @@ let newline = Format.pp_force_newline
|
||||||
let substring out (s, i, len) : unit = string out (String.sub s i len)
|
let substring out (s, i, len) : unit = string out (String.sub s i len)
|
||||||
let text = Format.pp_print_text
|
let text = Format.pp_print_text
|
||||||
let option = Format.pp_print_option
|
let option = Format.pp_print_option
|
||||||
let opt = option
|
|
||||||
let result = Format.pp_print_result
|
let result = Format.pp_print_result
|
||||||
|
|
||||||
let string_lines out (s : string) : unit =
|
let string_lines out (s : string) : unit =
|
||||||
|
|
@ -91,6 +90,11 @@ let iter ?(sep = return ",@ ") pp fmt seq =
|
||||||
sep fmt ();
|
sep fmt ();
|
||||||
pp fmt x)
|
pp fmt x)
|
||||||
|
|
||||||
|
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 ?(sep = return ",@ ") ppa ppb fmt (a, b) =
|
let pair ?(sep = return ",@ ") ppa ppb fmt (a, b) =
|
||||||
Format.fprintf fmt "%a%a%a" ppa a sep () ppb b
|
Format.fprintf fmt "%a%a%a" ppa a sep () ppb b
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,16 @@ val seq : ?sep:unit printer -> 'a printer -> 'a Seq.t printer
|
||||||
val iter : ?sep:unit printer -> 'a printer -> 'a iter printer
|
val iter : ?sep:unit printer -> 'a printer -> 'a iter printer
|
||||||
|
|
||||||
val option : ?none:unit printer -> 'a printer -> 'a option printer
|
val option : ?none:unit printer -> 'a printer -> 'a option printer
|
||||||
(** [opt ?none pp] prints options as follows:
|
(** [option ?none pp] prints options as follows:
|
||||||
- [Some x] will become [pp x]
|
- [Some x] will become [pp x]
|
||||||
- [None] will become [none ()]
|
- [None] will become [none ()]
|
||||||
|
Alias of {!Format.pp_print_option}
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val opt : ?none:unit printer -> 'a printer -> 'a option printer
|
val opt : 'a printer -> 'a option printer
|
||||||
(** Alias of {!option} *)
|
(** [opt pp] prints options as follows:
|
||||||
|
- [Some x] will become "some foo" if [pp x ---> "foo"].
|
||||||
|
- [None] will become "none". *)
|
||||||
|
|
||||||
val result : ok:'a printer -> error:'e printer -> ('a, 'e) result printer
|
val result : ok:'a printer -> error:'e printer -> ('a, 'e) result printer
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue