Skip to content

Commit

Permalink
Add convenience pretty printer for Either.t (added in 4.12) (#10242)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oghenevwogaga Ebresafe committed Apr 21, 2021
1 parent 2217ed8 commit 94faefd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -141,6 +141,10 @@ Working version
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:

- #10047: Add `Unix.realpath`
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 _].
@since 4.13 *)

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

(**
Expand Down

0 comments on commit 94faefd

Please sign in to comment.