diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index c99aae73..d01f3ad9 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -133,6 +133,11 @@ let some pp out = function | None -> () | Some x -> pp out x +let lazy_force pp out (lazy x) = pp out x + +let lazy_or ?(default=return "") pp out x = + if Lazy.is_val x then pp out (Lazy.force x) else default out () + (** {2 IO} *) let output fmt pp x = pp fmt x diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index c750e9e3..1fa0cdfe 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -129,6 +129,15 @@ val some : 'a printer -> 'a option printer @since 1.0 *) +val lazy_force : 'a printer -> 'a lazy_t printer +(** [lazy_force pp out x] forces [x] and prints the result with [pp] + @since NEXT_RELEASE *) + +val lazy_or : ?default:unit printer -> 'a printer -> 'a lazy_t printer +(** [lazy_or ?default pp out x] prints [default] if [x] is not + evaluated yet, or uses [pp] otherwise + @since NEXT_RELEASE *) + (** {2 ANSI codes} Use ANSI escape codes https://en.wikipedia.org/wiki/ANSI_escape_code