Add a chunk procedure

Just a variant of chunk! which doesn't modify the provided list.
This commit is contained in:
Christopher Baines 2021-10-03 14:54:10 +01:00
parent af0a06d147
commit 0796cb3bd3

View file

@ -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)