diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index 9dd8037c..3afcf352 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -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 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 = @@ -91,6 +90,11 @@ 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 diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index 12b1ca81..ec225687 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -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 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] - [None] will become [none ()] + Alias of {!Format.pp_print_option} @since NEXT_RELEASE *) -val opt : ?none:unit printer -> 'a printer -> 'a option printer -(** Alias of {!option} *) +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 result : ok:'a printer -> error:'e printer -> ('a, 'e) result printer