diff options
author | Christopher Baines <mail@cbaines.net> | 2021-10-03 14:54:10 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-10-03 14:54:10 +0100 |
commit | 0796cb3bd38b8462ccc7ada22f5504e43f88923f (patch) | |
tree | 2e30ca07f08c077734e4a45eebecd58abdd351ff | |
parent | af0a06d1476a14da4d36e438b284840ed8552d44 (diff) | |
download | data-service-0796cb3bd38b8462ccc7ada22f5504e43f88923f.tar data-service-0796cb3bd38b8462ccc7ada22f5504e43f88923f.tar.gz |
Add a chunk procedure
Just a variant of chunk! which doesn't modify the provided list.
-rw-r--r-- | guix-data-service/utils.scm | 11 |
1 files changed, 11 insertions, 0 deletions
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) |