summaryrefslogtreecommitdiff
path: root/gnu/services/configuration.scm
diff options
context:
space:
mode:
authorAttila Lendvai <attila@lendvai.name>2022-08-24 14:40:40 +0200
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-08-24 23:27:54 -0400
commitcc32cd41f74c642583837b43444646d52b3fd5da (patch)
tree11de168365afa4410c277de66d909270c3a69f1e /gnu/services/configuration.scm
parent147f8f19f844b8acc602ddcb49b4a1c0b9226c4d (diff)
services: configuration: Add maybe-value exported procedure.
* gnu/services/configuration.scm (maybe-value): New procedure. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Diffstat (limited to 'gnu/services/configuration.scm')
-rw-r--r--gnu/services/configuration.scm10
1 files changed, 10 insertions, 0 deletions
diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index a9426066b9..60965486a7 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -58,6 +58,7 @@
define-maybe
define-maybe/no-serialization
%unset-value
+ maybe-value
maybe-value-set?
generate-documentation
configuration->documentation
@@ -315,6 +316,15 @@ does not have a default value" field kind)))
"Predicate to check whether a 'maybe' value was explicitly provided."
(not (eq? %unset-value value)))
+;; Ideally there should be a compiler macro for this predicate, that expands
+;; to a conditional that only instantiates the default value when needed.
+(define* (maybe-value value #:optional (default #f))
+ "Returns VALUE, unless it is the unset value, in which case it returns
+DEFAULT."
+ (if (maybe-value-set? value)
+ value
+ default))
+
;; A little helper to make it easier to document all those fields.
(define (generate-documentation documentation documentation-name)
(define (str x) (object->string x))