mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add CCFormat.Dump.{result,to_string}
This commit is contained in:
parent
c89186a100
commit
d4d7bc1de2
2 changed files with 11 additions and 0 deletions
|
|
@ -342,10 +342,17 @@ module Dump = struct
|
||||||
let pair p1 p2 = pair p1 p2
|
let pair p1 p2 = pair p1 p2
|
||||||
let triple p1 p2 p3 = triple p1 p2 p3
|
let triple p1 p2 p3 = triple p1 p2 p3
|
||||||
let quad p1 p2 p3 p4 = quad p1 p2 p3 p4
|
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
|
end
|
||||||
|
|
||||||
(*$= & ~printer:(fun s->s)
|
(*$= & ~printer:(fun s->s)
|
||||||
"[1;2;3]" (to_string Dump.(list int) [1;2;3])
|
"[1;2;3]" (to_string Dump.(list int) [1;2;3])
|
||||||
"Some 1" (to_string Dump.(option int) (Some 1))
|
"Some 1" (to_string Dump.(option int) (Some 1))
|
||||||
"[None;Some \"a b\"]" (to_string Dump.(list (option string)) [None; Some "a b"])
|
"[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"])
|
||||||
*)
|
*)
|
||||||
|
|
|
||||||
|
|
@ -235,4 +235,8 @@ module Dump : sig
|
||||||
val quad :
|
val quad :
|
||||||
'a t -> 'b t -> 'c t -> 'd t ->
|
'a t -> 'b t -> 'c t -> 'd t ->
|
||||||
('a * 'b * 'c * '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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue