From 3d7035e84f2bff0a120f14ab4f08c287324afd4c Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 2 Sep 2015 21:05:17 +0200 Subject: [PATCH] add `CCOpt.print` --- src/core/CCOpt.ml | 6 ++++++ src/core/CCOpt.mli | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index 9a792fd0..76d0d9ad 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -147,6 +147,7 @@ let of_list = function type 'a sequence = ('a -> unit) -> unit type 'a gen = unit -> 'a option type 'a printer = Buffer.t -> 'a -> unit +type 'a fmt = Format.formatter -> 'a -> unit type 'a random_gen = Random.State.t -> 'a let random g st = @@ -166,3 +167,8 @@ let to_seq o k = match o with let pp ppx buf o = match o with | None -> Buffer.add_string buf "None" | Some x -> Buffer.add_string buf "Some "; ppx buf x + +let print ppx out = function + | None -> Format.pp_print_string out "None" + | Some x -> Format.fprintf out "@[Some %a@]" ppx x + diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index ed1f3778..1093dbe8 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -121,6 +121,7 @@ val of_list : 'a list -> 'a t type 'a sequence = ('a -> unit) -> unit type 'a gen = unit -> 'a option type 'a printer = Buffer.t -> 'a -> unit +type 'a fmt = Format.formatter -> 'a -> unit type 'a random_gen = Random.State.t -> 'a val random : 'a random_gen -> 'a t random_gen @@ -130,3 +131,6 @@ val to_seq : 'a t -> 'a sequence val pp : 'a printer -> 'a t printer +val print : 'a fmt -> 'a t fmt +(** @since NEXT_RELEASE *) +