[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/6] services: Add 'lookup-service-types'.
From: |
Ludovic Courtès |
Subject: |
[PATCH 5/6] services: Add 'lookup-service-types'. |
Date: |
Wed, 8 Nov 2017 14:09:20 +0100 |
* gnu/services.scm (lookup-service-types): New procedure.
* tests/services.scm ("lookup-service-types"): New test.
---
gnu/services.scm | 11 +++++++++++
tests/services.scm | 10 +++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gnu/services.scm b/gnu/services.scm
index df1bedeb9..016ff08e0 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -55,6 +55,7 @@
%service-type-path
fold-service-types
+ lookup-service-types
service
service?
@@ -192,6 +193,16 @@ is used as the initial value of RESULT."
seed
modules))
+(define lookup-service-types
+ (let ((table
+ (delay (fold-service-types (lambda (type result)
+ (vhash-consq (service-type-name type)
+ type result))
+ vlist-null))))
+ (lambda (name)
+ "Return the list of services with the given NAME (a symbol)."
+ (vhash-foldq* cons '() name (force table)))))
+
;; Services of a given type.
(define-record-type <service>
(make-service type value)
diff --git a/tests/services.scm b/tests/services.scm
index 8484ee982..ca32b565c 100644
--- a/tests/services.scm
+++ b/tests/services.scm
@@ -23,7 +23,8 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
- #:use-module (srfi srfi-64))
+ #:use-module (srfi srfi-64)
+ #:use-module (ice-9 match))
(define live-service
(@@ (gnu services herd) live-service))
@@ -206,4 +207,11 @@
(list (map live-service-provision unload)
(map shepherd-service-provision load)))))
+(test-eq "lookup-service-types"
+ system-service-type
+ (and (null? (lookup-service-types 'does-not-exist-at-all))
+ (match (lookup-service-types 'system)
+ ((one) one)
+ (x x))))
+
(test-end)
--
2.15.0
- [PATCH] Re: The usability of Guix configurations, (continued)
- Reporting module errors, Ludovic Courtès, 2017/11/07
- Re: Reporting module errors, myglc2, 2017/11/07
- Re: Reporting module errors, Hartmut Goebel, 2017/11/08
- Re: Reporting module errors, Ludovic Courtès, 2017/11/08
- [PATCH 0/6] Error reporting and hints for missing modules, Ludovic Courtès, 2017/11/08
- [PATCH 1/6] ui: Introduce (guix i18n)., Ludovic Courtès, 2017/11/08
- [PATCH 3/6] services: 'fold-service-types' honors its seed., Ludovic Courtès, 2017/11/08
- [PATCH 5/6] services: Add 'lookup-service-types'.,
Ludovic Courtès <=
- [PATCH 4/6] services: 'fold-service-types' includes (gnu services)., Ludovic Courtès, 2017/11/08
- [PATCH 2/6] ui: Define and honor '&error-location' and '&fix-hint' conditions., Ludovic Courtès, 2017/11/08
- [PATCH 6/6] gnu: Improve error reporting of the use-.*modules macros., Ludovic Courtès, 2017/11/08
- Re: [PATCH 6/6] gnu: Improve error reporting of the use-.*modules macros., Chris Marusich, 2017/11/10
- Re: [PATCH 6/6] gnu: Improve error reporting of the use-.*modules macros., Ludovic Courtès, 2017/11/11
- Re: [PATCH 6/6] gnu: Improve error reporting of the use-.*modules macros., Chris Marusich, 2017/11/11
- Re: [PATCH 0/6] Error reporting and hints for missing modules, julien lepiller, 2017/11/08
- Re: [PATCH 0/6] Error reporting and hints for missing modules, myglc2, 2017/11/08
- Re: [PATCH 0/6] Error reporting and hints for missing modules, myglc2, 2017/11/08
- Re: [PATCH 0/6] Error reporting and hints for missing modules, Ludovic Courtès, 2017/11/08