Commit 48094c99 authored by Julien's avatar Julien Committed by Grégoire Henry

Stdlib: add `Option.pp`

parent be5f985e
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment