diff options
author | Colin Okay <okay@toyful.space> | 2022-07-30 12:09:28 -0500 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-07-30 12:09:28 -0500 |
commit | 79aa98de8bed02a14d5bdb76edc87865c4663053 (patch) | |
tree | 42da8542318e72fbbc2c01aef378d90dee1ebef3 | |
parent | 8ea37e94836473f0c69af94aac2aa2d403599d0b (diff) |
[refactor] group
-rw-r--r-- | hyperquirks.lisp | 15 |
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 |