diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index a02f6b23..85ec6bfc 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -342,10 +342,17 @@ module Dump = struct let pair p1 p2 = pair p1 p2 let triple p1 p2 p3 = triple p1 p2 p3 let quad p1 p2 p3 p4 = quad p1 p2 p3 p4 + let result' pok perror out = function + | Result.Ok x -> Format.fprintf out "Ok %a" pok x + | Result.Error e -> Format.fprintf out "Error %a" perror e + let result pok = result' pok string + let to_string = to_string end (*$= & ~printer:(fun s->s) "[1;2;3]" (to_string Dump.(list int) [1;2;3]) "Some 1" (to_string Dump.(option int) (Some 1)) "[None;Some \"a b\"]" (to_string Dump.(list (option string)) [None; Some "a b"]) + "[Ok \"a b c\";Error \"nope\"]" \ + (to_string Dump.(list (result string)) [Result.Ok "a b c"; Result.Error "nope"]) *) diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index ec7c6efd..9b6546a5 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -235,4 +235,8 @@ module Dump : sig val quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t + val result : 'a t -> ('a, string) Result.result t + val result' : 'a t -> 'e t -> ('a, 'e) Result.result t + val to_string : 'a t -> 'a -> string + (** Alias to {!to_string} *) end