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 6 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
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Working version
The Standard Library generated by the Dune rules is now equivalent to the main
build (the Dune rules still do not generate a distributable compiler).
(David Allsopp and Mark Shinwell, review by Gabriel Scherer)

- #10242: Added convenience pretty printer for Either.t in the Format module.
(Oghenevwogaga Ebresafe, review by Nicolás Ojeda Bär, Gabriel Scherer and Xavier Van de Woestyne)

### Other libraries:

Expand Down
4 changes: 4 additions & 0 deletions stdlib/format.ml
Original file line number Diff line number Diff line change
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
8 changes: 8 additions & 0 deletions stdlib/format.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,14 @@ 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

@since 4.13 *)

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

(**
Expand Down