Function: seq-split
seq-split is a byte-compiled function defined in seq.el.gz.
Signature
(seq-split SEQUENCE LENGTH)
Documentation
Split SEQUENCE into a list of sub-sequences of at most LENGTH elements.
All the sub-sequences will be LENGTH long, except the last one, which may be shorter.
Other relevant functions are documented in the sequence group.
Probably introduced at or before Emacs version 29.1.
Shortdoc
;; sequence
(seq-split [0 1 2 3 5] 2)
=> ([0 1] [2 3] [5])
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/seq.el.gz
(defun seq-split (sequence length)
"Split SEQUENCE into a list of sub-sequences of at most LENGTH elements.
All the sub-sequences will be LENGTH long, except the last one,
which may be shorter."
(when (< length 1)
(error "Sub-sequence length must be larger than zero"))
(let ((result nil)
(seq-length (length sequence))
(start 0))
(while (< start seq-length)
(push (seq-subseq sequence start
(setq start (min seq-length (+ start length))))
result))
(nreverse result)))