[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#73202] [PATCH v3 06/14] guix: utils: Add flatten and flat-map from
From: |
Herman Rimm |
Subject: |
[bug#73202] [PATCH v3 06/14] guix: utils: Add flatten and flat-map from haunt. |
Date: |
Thu, 26 Sep 2024 12:09:03 +0200 |
* guix/utils.scm (flatten, flat-map): Add procedures.
Change-Id: I1d7d49fd02115e3de09ed69bcf5f55a10423162e
---
guix/utils.scm | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/guix/utils.scm b/guix/utils.scm
index f161cb4ef3..2740552a75 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -139,6 +139,9 @@ (define-module (guix utils)
with-environment-variables
arguments-from-environment-variable
+ flatten
+ flat-map
+
config-directory
cache-directory
@@ -1028,6 +1031,29 @@ (define (with-atomic-file-output file proc)
(false-if-exception (delete-file template))
(close-port out)))))
+;; TODO: bring over other utility procedures from (haunt utils).
+(define* (flatten lst #:optional depth)
+ "Return a list that recursively concatenates the sub-lists of LST,
+up to DEPTH levels deep. When DEPTH is #f, the entire tree is
+flattened."
+ (if (and (number? depth) (zero? depth))
+ lst
+ (fold-right (match-lambda*
+ (((sub-list ...) memo)
+ (append (flatten sub-list (and depth (1- depth)))
+ memo))
+ ((elem memo)
+ (cons elem memo)))
+ '()
+ lst)))
+
+(define (flat-map proc . lsts)
+ "Apply PROC to each element of each list in LSTS and return a new
+list in which nested lists are concatenated into the result.
+
+For example, the list (1 2 (3)) would be flattened to (1 2 3)."
+ (flatten (apply map proc lsts) 1))
+
(define* (xdg-directory variable suffix #:key (ensure? #t))
"Return the name of the XDG directory that matches VARIABLE and SUFFIX,
after making sure that it exists if ENSURE? is true. VARIABLE is an
--
2.45.2
- [bug#73202] [PATCH v2 15/15] teams: Add bootloading team., (continued)
- [bug#73202] [PATCH v2 00/15] Preparation for bootloader rewrite., Herman Rimm, 2024/09/21
- [bug#73202] [PATCH v3 01/14] gnu: bootloader: Remove deprecated bootloader-configuration field., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 02/14] gnu: system: Remove useless boot parameters., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 03/14] gnu: tests: reconfigure: Remove bootloader install test., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 08/14] gnu: bootloader: Add bootloader-target record and infastructure., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 09/14] gnu: bootloader: Add bootloader-configurations->gexp., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 06/14] guix: utils: Add flatten and flat-map from haunt.,
Herman Rimm <=
- [bug#73202] [PATCH v3 07/14] guix: records: Add wrap-element procedure., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 11/14] gnu: build: bootloader: Add efi-bootnums procedure., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 13/14] gnu: bootloader: Match records outside the module., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 10/14] gnu: bootloader: Add device-subvol field to menu-entry record., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 05/14] guix: scripts: Rewrite reinstall-bootloader to use provenance data., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 04/14] guix: scripts: Remove unused code., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 14/14] teams: Add bootloading team., Herman Rimm, 2024/09/26
- [bug#73202] [PATCH v3 12/14] gnu: bootloader: Install any bootloader to ESP., Herman Rimm, 2024/09/26