diff options
author | Ludovic Courtès <ludo@gnu.org> | 2013-07-10 18:04:08 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-07-10 21:52:51 +0200 |
commit | c8772a7a21f954b5e75746529e70edc3a1017249 (patch) | |
tree | 03792f0a3dd41d5af5d4bf833bf6bfcebb992ae8 /guix | |
parent | b7b88288011aa41791b6634ae229f426bacc55ce (diff) | |
download | gnu-guix-c8772a7a21f954b5e75746529e70edc3a1017249.tar gnu-guix-c8772a7a21f954b5e75746529e70edc3a1017249.tar.gz |
records: `alist->record' supports multiple-field occurrences.
* guix/records.scm (alist->record): Add `multiple-value-keys'
parameter. Update docstring, and honor it.
* tests/records.scm ("alist->record"): New record.
Diffstat (limited to 'guix')
-rw-r--r-- | guix/records.scm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/guix/records.scm b/guix/records.scm index 57664df5a6..8dc733b8ff 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -198,9 +198,19 @@ thunked fields." #'((field options ...) ...)))))))))) -(define (alist->record alist make keys) - "Apply MAKE to the values associated with KEYS in ALIST." - (let ((args (map (cut assoc-ref alist <>) keys))) +(define* (alist->record alist make keys + #:optional (multiple-value-keys '())) + "Apply MAKE to the values associated with KEYS in ALIST. Items in KEYS that +are also in MULTIPLE-VALUE-KEYS are considered to occur possibly multiple +times in ALIST, and thus their value is a list." + (let ((args (map (lambda (key) + (if (member key multiple-value-keys) + (filter-map (match-lambda + ((k . v) + (and (equal? k key) v))) + alist) + (assoc-ref alist key))) + keys))) (apply make args))) (define (object->fields object fields port) |