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

commit 0796cb3bd38b8462ccc7ada22f5504e43f88923f
Author: Christopher Baines <[email protected]>
AuthorDate: Sun Oct 3 14:54:10 2021 +0100

    Add a chunk procedure
    
    Just a variant of chunk! which doesn't modify the provided list.
---
 guix-data-service/utils.scm | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/guix-data-service/utils.scm b/guix-data-service/utils.scm
index c45f518..4f66c9c 100644
--- a/guix-data-service/utils.scm
+++ b/guix-data-service/utils.scm
@@ -31,6 +31,7 @@
             par-map&
             letpar&
 
+            chunk
             chunk!))
 
 (define (call-with-time-logging action thunk)
@@ -155,6 +156,16 @@
 
 (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)))
+
 (define (chunk! lst max-length)
   (if (> (length lst)
          max-length)

Reply via email to