Stdlib: add Option.pp

This commit is contained in:
Julien Tesson 2018-10-24 17:17:18 +02:00 committed by Grégoire Henry
parent be5f985ec7
commit 48094c9989
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
2 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,7 @@
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* Copyright (c) 2019 Nomadic Labs, <contact@nomadic-labs.com> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
@ -59,3 +60,9 @@ let try_with f =
try Some (f ()) with _ -> None
let some x = Some x
let pp ?(default="") data_pp ppf opt =
unopt_map
~f:(fun i -> data_pp ppf i)
~default:(Format.pp_print_string ppf default)
opt

View File

@ -2,6 +2,7 @@
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* Copyright (c) 2019 Nomadic Labs, <contact@nomadic-labs.com> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
@ -52,3 +53,7 @@ val try_with : (unit -> 'a) -> 'a option
(** Make an option of a value *)
val some : 'a -> 'a option
(** [pp ~default data_pp ppf x] pretty-print value [x] using [data_pp]
or [default] ([""] by default) string if there is no value. *)
val pp: ?default:string ->(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a option -> unit