From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id mJZEACdR7WaxgwEA62LTzQ:P1 (envelope-from ) for ; Fri, 20 Sep 2024 10:40:39 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id mJZEACdR7WaxgwEA62LTzQ (envelope-from ) for ; Fri, 20 Sep 2024 12:40:39 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=XuNucUXa; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=oRemBdjr; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1726828838; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=vfcqcX2IoxjeLL2a13Hzs5VnUYGnh2RdWddfI6pSBb8=; b=t1bzyY+mzHEyPVekQHTGuOKt99GlGMZwoHv5VwAtI8e5X8ixomL+h8AY6Tyg48yjOLp2aj eiNtgybLWfqP7K/Dfyom3lLcQBjrU/fQysiqqO/MvkcWshRet+lr4VXMchU7GuHG4/qXAZ EeQGakw0B3YOrgrprb7BGGrgpoyhItS9tfFNFORoA49oOh6sob80yvHmkid1TxvXPmXbix kkgTh4OK1yOG4gtuGa9YeQEWyERSBe/VhW49MJx0vAhdSyi6LRG/tqd+n2Vi/t7kmHjNrw 8QpBPFEmLFX9Wn67CTnVZcNjdpbfZmS2fML7CsibxF+2ymRk7f8VUXgXSgLYWA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1726828838; a=rsa-sha256; cv=none; b=L4y/Gp648+SH8t/OYh/TxI8rZe6woByIAPGkEoA2kLNjjm3PQT82w9l1xSaFLE3teYv7kG S2yi2zRzKuNF7HbDMl+SL3n7gVP3Cg3SnGP1EMNOgbXxMtvXru4e9AQFfAeYEg4biX3uRd cA5B9cMBWp0reIrFdiAuDJEcY1HnlEj9gHghQ8nMYopdDuP75uQyckpsJQmuYcv/2CDLhU o6U3jmMHOXZv+ULzZ8vArzb3gUx03NgFbyec1Ra1tlgZYHV7Eu41FZITEPFWh1By/eaYWC 8K0x0A+trfMAjFc6WzAuvrs9cc0NSzwZTt7hAr0K8WLbvJL/j/lyeHvzCh/VXQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=XuNucUXa; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=oRemBdjr; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D44717BAE9 for ; Fri, 20 Sep 2024 12:40:38 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srb3g-0005ET-G0; Fri, 20 Sep 2024 06:40:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srb3F-0004xw-Cf for guix-patches@gnu.org; Fri, 20 Sep 2024 06:39:49 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1srb3F-0006UA-43; Fri, 20 Sep 2024 06:39:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=vfcqcX2IoxjeLL2a13Hzs5VnUYGnh2RdWddfI6pSBb8=; b=XuNucUXaYebXihfXq8iVCpYuc8ydOgpezKs/JdxbyyqsMf+jwjDLFbMi51qFOjeJQrsC8U62gULyZOADl6OHA9jvV9hOEe2mRqf5SD/zgm/Uoa3aJUZtPcqCz0DTXAnXUmuHgvgNiPA7dLX3P6EV9qJ1wSH5+ykLKRjaWqnT3z9iVdu6N9LhfIQNo9AUIB9h7U2rM7SR68UKcN8Zp5YKktyfoHIOhjt6ToIWNTWlEG3axSmWpAkz8JLFv1kQrAueHaNygg5j9NzYtICbmGZbZqgVM3MMoGmHpR+h0Q9eHmOobloepNJHecrQA6S7TFLZ+auq32IVL+oL30v75gJkvg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1srb3V-0001PN-KY; Fri, 20 Sep 2024 06:40:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73202] [PATCH v2 06/15] guix: utils: Add flatten and flat-map from haunt. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 20 Sep 2024 10:40:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73202 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73202@debbugs.gnu.org Cc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 73202-submit@debbugs.gnu.org id=B73202.17268287795268 (code B ref 73202); Fri, 20 Sep 2024 10:40:05 +0000 Received: (at 73202) by debbugs.gnu.org; 20 Sep 2024 10:39:39 +0000 Received: from localhost ([127.0.0.1]:34161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srb35-0001Mt-5j for submit@debbugs.gnu.org; Fri, 20 Sep 2024 06:39:39 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:54361 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srb2q-0001KU-PA for 73202@debbugs.gnu.org; Fri, 20 Sep 2024 06:39:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1726828735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vfcqcX2IoxjeLL2a13Hzs5VnUYGnh2RdWddfI6pSBb8=; b=oRemBdjrHe3H7OwyDwiEzYFou91OamSy9W6i3r5pyJr0HR8m3YKNs9GS2fedgL/Xbx2aqB momiG8p5oTUg/bTb+eBdmWPQnQkeC03rVaiOJnsQu4t1lnEmvcBawhG00RCdUku3ioL/1G sRLrw+kZLu4xsF8C2QHa+SxezBAmfJ/RFRB/NLRr7AnFDo6SdwHbqJ+0uI5l2wk73Vp9N9 UTkZ5lYvBuc2HdsfpC7usXTBvWx90wMuVSd+ha35na4MfrNs0k5F6IU786dTTFNDzUBK8+ BykVqZUEUq1uRimqOqngvHrDUxKPa2Gy8DNGuljQYQUBp32+KK848D5nT8wiIw== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 74a9aac9 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for <73202@debbugs.gnu.org>; Fri, 20 Sep 2024 10:38:55 +0000 (UTC) Date: Fri, 20 Sep 2024 12:37:51 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches From: Herman Rimm via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -5.01 X-Migadu-Queue-Id: D44717BAE9 X-Spam-Score: -5.01 X-TUID: c5tr6UmVpogy * 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 d8ce6ed886..e37c2d8770 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 @@ -1027,6 +1030,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