mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -05:00
CCFormat(feat): add option and result, change opt
Add CCFormat.option and CCFormat.result as aliases to Format.pp_print_option and Format.pp_print_result. Make CCFormat.opt an alias of CCFormat.option, as such this add an optional argument to print the case "None" but change the default behaviour. Previously, it as printing "some _" or "none" now it print something only in the case of "Some x" and just "x".
This commit is contained in:
parent
2aa8416b1c
commit
1de3036e0c
2 changed files with 13 additions and 9 deletions
|
|
@ -31,6 +31,9 @@ let break fmt (m, n) = Format.pp_print_break fmt m n
|
|||
let newline = Format.pp_force_newline
|
||||
let substring out (s, i, len) : unit = string out (String.sub s i len)
|
||||
let text = Format.pp_print_text
|
||||
let option = Format.pp_print_option
|
||||
let opt = option
|
||||
let result = Format.pp_print_result
|
||||
|
||||
let string_lines out (s : string) : unit =
|
||||
fprintf out "@[<v>";
|
||||
|
|
@ -88,11 +91,6 @@ let iter ?(sep = return ",@ ") pp fmt seq =
|
|||
sep fmt ();
|
||||
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) =
|
||||
Format.fprintf fmt "%a%a%a" ppa a sep () ppb b
|
||||
|
||||
|
|
|
|||
|
|
@ -99,10 +99,16 @@ val arrayi : ?sep:unit printer -> (int * 'a) printer -> 'a array printer
|
|||
val seq : ?sep:unit printer -> 'a printer -> 'a Seq.t printer
|
||||
val iter : ?sep:unit printer -> 'a printer -> 'a iter printer
|
||||
|
||||
val opt : 'a printer -> 'a option printer
|
||||
(** [opt pp] prints options as follows:
|
||||
- [Some x] will become "some foo" if [pp x ---> "foo"].
|
||||
- [None] will become "none". *)
|
||||
val option : ?none:unit printer -> 'a printer -> 'a option printer
|
||||
(** [opt ?none pp] prints options as follows:
|
||||
- [Some x] will become [pp x]
|
||||
- [None] will become [none ()]
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val opt : ?none:unit printer -> 'a printer -> 'a option printer
|
||||
(** Alias of {!option} *)
|
||||
|
||||
val result : ok:'a printer -> error:'e printer -> ('a, 'e) result printer
|
||||
|
||||
(** In the tuple printers, the [sep] argument is only available.
|
||||
@since 0.17 *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue