Skip to content

Commit

Permalink
Add Format.pp_print_result.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuenzli committed Aug 6, 2018
1 parent e4869ac commit e757037
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stdlib/format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,10 @@ let pp_print_text ppf s =
done;
if !left <> len then flush ()

let pp_print_result ~ok ~error ppf = function
| Ok v -> ok ppf v
| Error e -> error ppf e

(**************************************************************)

let compute_tag output tag_acc =
Expand Down
8 changes: 8 additions & 0 deletions stdlib/format.mli
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,14 @@ val pp_print_text : formatter -> string -> unit
@since 4.02.0
*)

val pp_print_result :
ok:(formatter -> 'a -> unit) -> error:(formatter -> 'e -> unit) ->
formatter -> ('a, 'e) result -> unit
(** [pp_print_result ~ok ~error ppf r] prints [r] on [ppf] using
[ok] if [r] is [Ok _] and [error] if [r] is [Error _].
@since 4.08 *)

(** {1:fpp Formatted pretty-printing} *)

(**
Expand Down

0 comments on commit e757037

Please sign in to comment.