services: configuration: Add maybe-value exported procedure.
* gnu/services/configuration.scm (maybe-value): New procedure. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
parent
147f8f19f8
commit
cc32cd41f7
@ -58,6 +58,7 @@
|
|||||||
define-maybe
|
define-maybe
|
||||||
define-maybe/no-serialization
|
define-maybe/no-serialization
|
||||||
%unset-value
|
%unset-value
|
||||||
|
maybe-value
|
||||||
maybe-value-set?
|
maybe-value-set?
|
||||||
generate-documentation
|
generate-documentation
|
||||||
configuration->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."
|
"Predicate to check whether a 'maybe' value was explicitly provided."
|
||||||
(not (eq? %unset-value value)))
|
(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.
|
;; A little helper to make it easier to document all those fields.
|
||||||
(define (generate-documentation documentation documentation-name)
|
(define (generate-documentation documentation documentation-name)
|
||||||
(define (str x) (object->string x))
|
(define (str x) (object->string x))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user