Stdlib: add Option.pp
This commit is contained in:
parent
be5f985ec7
commit
48094c9989
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user