Subject: [PATCH 1/5] utils: Add insert-before.

From: [email-masked]
Date: Thu, 8 Jun 2023 17:14:35 +0200

From: Carlos Durán Domínguez <[email-masked]>

---
 guix/utils.scm | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/guix/utils.scm b/guix/utils.scm
index b9657df292..5773b55116 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <[email-masked]>
 ;;; Copyright © 2022 Antero Mejr <[email-masked]>
 ;;; Copyright © 2023 Philip McGrath <[email-masked]>
+;;; Copyright © 2023 Carlos Durán Domínguez <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -149,7 +150,9 @@ (define-module (guix utils)
             string-distance
             string-closest
 
-            pretty-print-table))
+            pretty-print-table
+
+            insert-before))
 
 
 ;;;
@@ -1128,6 +1131,19 @@ (define* (string-closest trial tests #:key (threshold 3))
            #f +inf.0
            tests)))
 
+
+;;;
+;;; List modification.
+;;;
+
+(define (insert-before pred lst1 lst2)
+  "Return a list appending LST2 just before the first element on LST1 that
+ satisfy the predicate PRED."
+  (cond
+   ((null? lst1) lst2)
+   ((pred (car lst1)) (append lst2 lst1))
+   (else (cons (car lst1) (insert-before pred (cdr lst1) lst2)))))
+
 
 ;;;
 ;;; Prettified output.
-- 
2.40.1