diff options
author | Nicolas Graves <ngraves@ngraves.fr> | 2025-09-11 00:02:34 +0200 |
---|---|---|
committer | Jelle Licht <jlicht@fsfe.org> | 2025-10-13 10:26:39 +0200 |
commit | 01b321e8894808af887f6845055afb68c959a8d0 (patch) | |
tree | e444c5b2a3db0315833ad24b8dffc5630a16d475 | |
parent | 287a767b87cf150d9d2ed2a704b434c7e7d39d6b (diff) |
build-system: node: Remove alist-pop, simplify alist-update.
Those functions are most likely not worth the complexity they carry.
They might be a little more efficient (stop at the first encounter
instead of mapping until the end), but is it worth the additional
complexity? I'm unsure.
* guix/build/node-build-system.scm (alist-pop): Remove variable.
(alist-update): Use a more standard map.
Change-Id: I47b91461849d6e6d627e98f67bc6a08f12fa7370
Signed-off-by: Jelle Licht <jlicht@fsfe.org>
-rw-r--r-- | guix/build/node-build-system.scm | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index 18c331ab18..b52fbe847a 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -30,6 +30,7 @@ #:use-module (ice-9 match) #:use-module (json) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-71) #:export (%standard-phases delete-dependencies @@ -41,27 +42,17 @@ replace-fields with-atomic-json-file-replacement)) -(define* (alist-pop alist key #:optional (= equal?)) - "Return two values, the first pair in ALIST with key KEY, and the other -elements. Equality calls are made as (= KEY ALISTCAR)." - (define (found? pair) - (= key (car pair))) - - (let ((before after (break found? alist))) - (if (pair? after) - (values (car after) (append before (cdr after))) - (values #f before)))) - (define* (alist-update alist key proc #:optional (= equal?)) "Return an association list like ALIST, but with KEY mapped to the result of PROC applied to the first value found under the comparison (= KEY ALISTCAR). -If no such value exists, return the list unchanged. -Unlike acons, this removes the previous association of KEY (assuming it is -unique), but the result may still share storage with ALIST." - (let ((pair rest (alist-pop alist key =))) - (if (pair? pair) - (acons key (proc (cdr pair)) rest) - alist))) +If no such value exists, return the list unchanged." + (map + (match-lambda + (((? (cut = key <>)) . value) + (cons key (proc value))) + (pair + pair)) + alist)) ;;; ;;; package.json modification procedures |