summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm29
1 files changed, 28 insertions, 1 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index d7c37e37d1..f13e585e2b 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -59,7 +59,8 @@
%current-system
version-compare
version>?
- package-name->name+version))
+ package-name->name+version
+ fold2))
;;;
@@ -463,6 +464,32 @@ introduce the version part."
((head tail ...)
(loop tail (cons head prefix))))))
+(define fold2
+ (case-lambda
+ ((proc seed1 seed2 lst)
+ "Like `fold', but with a single list and two seeds."
+ (let loop ((result1 seed1)
+ (result2 seed2)
+ (lst lst))
+ (if (null? lst)
+ (values result1 result2)
+ (call-with-values
+ (lambda () (proc (car lst) result1 result2))
+ (lambda (result1 result2)
+ (loop result1 result2 (cdr lst)))))))
+ ((proc seed1 seed2 lst1 lst2)
+ "Like `fold', but with a two lists and two seeds."
+ (let loop ((result1 seed1)
+ (result2 seed2)
+ (lst1 lst1)
+ (lst2 lst2))
+ (if (or (null? lst1) (null? lst2))
+ (values result1 result2)
+ (call-with-values
+ (lambda () (proc (car lst1) (car lst2) result1 result2))
+ (lambda (result1 result2)
+ (fold2 proc result1 result2 (cdr lst1) (cdr lst2)))))))))
+
;;;
;;; Source location.