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 all 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 Changes
Expand Up @@ -86,6 +86,10 @@ Working version
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:

* #10084: Unix.open_process_args* functions now look up the program in the PATH.
Expand Down
3 changes: 3 additions & 0 deletions stdlib/.depend
Expand Up @@ -269,6 +269,7 @@ stdlib__Format.cmo : format.ml \
stdlib__Queue.cmi \
stdlib__List.cmi \
stdlib__Int.cmi \
stdlib__Either.cmi \
camlinternalFormatBasics.cmi \
camlinternalFormat.cmi \
stdlib__Buffer.cmi \
Expand All @@ -281,13 +282,15 @@ stdlib__Format.cmx : format.ml \
stdlib__Queue.cmx \
stdlib__List.cmx \
stdlib__Int.cmx \
stdlib__Either.cmx \
camlinternalFormatBasics.cmx \
camlinternalFormat.cmx \
stdlib__Buffer.cmx \
stdlib__Format.cmi
stdlib__Format.cmi : format.mli \
stdlib.cmi \
stdlib__Seq.cmi \
stdlib__Either.cmi \
stdlib__Buffer.cmi
stdlib__Fun.cmo : fun.ml \
stdlib__Printexc.cmi \
Expand Down
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
8 changes: 8 additions & 0 deletions stdlib/format.mli
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