add CCFormat.Dump.{result,to_string}

This commit is contained in:
Simon Cruanes 2016-11-03 18:11:05 +01:00
parent c89186a100
commit d4d7bc1de2
2 changed files with 11 additions and 0 deletions

View file

@ -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"])
*)

View file

@ -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