guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/04: Add a chunk! untility


From: Christopher Baines
Subject: 01/04: Add a chunk! untility
Date: Sun, 3 Oct 2021 08:04:07 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit d5ab67000e613c2877e6f008cdb2b322701f5285
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Sun Oct 3 12:55:21 2021 +0100

    Add a chunk! untility
    
    For splitting a list in to multiple chuncks, satisfying some max length.
---
 guix-data-service/utils.scm | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/guix-data-service/utils.scm b/guix-data-service/utils.scm
index 7741671..c45f518 100644
--- a/guix-data-service/utils.scm
+++ b/guix-data-service/utils.scm
@@ -16,6 +16,7 @@
 ;;; <http://www.gnu.org/licenses/>.
 
 (define-module (guix-data-service utils)
+  #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
   #:use-module (ice-9 match)
   #:use-module (ice-9 threads)
@@ -28,7 +29,9 @@
 
             parallel-via-thread-pool-channel
             par-map&
-            letpar&))
+            letpar&
+
+            chunk!))
 
 (define (call-with-time-logging action thunk)
   (simple-format #t "debug: Starting ~A\n" action)
@@ -151,3 +154,13 @@
          '())))))
 
 (define par-map& (par-mapper' map cons))
+
+(define (chunk! lst max-length)
+  (if (> (length lst)
+         max-length)
+      (call-with-values (lambda ()
+                          (split-at! lst max-length))
+        (lambda (first-lst rest)
+          (cons first-lst
+                (chunk! rest max-length))))
+      (list lst)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]