guix-commits
[Top][All Lists]
Advanced

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

01/03: Add a chunk procedure


From: Christopher Baines
Subject: 01/03: Add a chunk procedure
Date: Sun, 3 Oct 2021 10:29:14 -0400 (EDT)

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

commit 0796cb3bd38b8462ccc7ada22f5504e43f88923f
Author: Christopher Baines <mail@cbaines.net>
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

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