summaryrefslogtreecommitdiff
path: root/hyperquirks.lisp
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-07-30 12:09:28 -0500
committerColin Okay <okay@toyful.space>2022-07-30 12:09:28 -0500
commit79aa98de8bed02a14d5bdb76edc87865c4663053 (patch)
tree42da8542318e72fbbc2c01aef378d90dee1ebef3 /hyperquirks.lisp
parent8ea37e94836473f0c69af94aac2aa2d403599d0b (diff)
[refactor] group
Diffstat (limited to 'hyperquirks.lisp')
-rw-r--r--hyperquirks.lisp15
1 files changed, 9 insertions, 6 deletions
diff --git a/hyperquirks.lisp b/hyperquirks.lisp
index dd65b4f..b765e69 100644
--- a/hyperquirks.lisp
+++ b/hyperquirks.lisp
@@ -208,12 +208,15 @@ E.g.
"Group a list XS into consequtive sublists of size N, using the
DEFAULT to fill in any remainder in the case the length of XS is not
neatly divisible by N."
- (loop for l on xs by (lambda (l) (nthcdr n l))
- when (<= n (length l))
- collect (subseq l 0 n)
- else
- collect (append l (loop repeat (- n (length l)) collect default))))
-
+ (loop
+ with len = (length xs)
+ for start from 0 to len by n
+ for end = (+ start n)
+ when (<= end len)
+ collect (subseq xs start end)
+ when (and (< start len) (> end len))
+ collect (nconc (subseq xs start)
+ (loop repeat (- end len) collect default))))
;;; STRING FUNCTIONS