Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience pretty printer for Either.t (added in 4.12) #10242

Merged
merged 9 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/format.ml
Expand Up @@ -1237,6 +1237,10 @@ let pp_print_result ~ok ~error ppf = function
| Ok v -> ok ppf v
| Error e -> error ppf e

let pp_print_either ~left ~right ppf = function
| Either.Left l -> left ppf l
| Either.Right r -> right ppf r

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

let compute_tag output tag_acc =
Expand Down
6 changes: 6 additions & 0 deletions stdlib/format.mli
Expand Up @@ -1120,6 +1120,12 @@ val pp_print_result :

@since 4.08 *)

val pp_print_either :
left:(formatter -> 'a -> unit) ->
right:(formatter -> 'b -> unit) -> formatter -> ('a, 'b) Either.t -> unit
(** [pp_print_either ~left ~right ppf e] prints [e] on [ppf] using
[left] if [e] is [Either.Left _] and [right] if [e] is [Either.Right _]. *)
ebresafegaga marked this conversation as resolved.
Show resolved Hide resolved

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

(**
Expand Down