Function: seq-partition

seq-partition is a byte-compiled function defined in seq.el.gz.

Signature

(seq-partition SEQUENCE N)

Documentation

Return list of elements of SEQUENCE grouped into sub-sequences of length N.

The last sequence may contain less than N elements. If N is a negative integer or 0, the function returns nil. This does not modify SEQUENCE.

Other relevant functions are documented in the sequence group.

View in manual

Shortdoc

;; sequence
(seq-partition '(a b c d e f g h) 3)
    => ((a b c) (d e f) (g h))

Implementations

(seq-partition SEQUENCE N) in `seq.el'.

Undocumented

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/seq.el.gz
(cl-defgeneric seq-partition (sequence n)
  "Return list of elements of SEQUENCE grouped into sub-sequences of length N.
The last sequence may contain less than N elements.  If N is a
negative integer or 0, the function returns nil.
This does not modify SEQUENCE."
  (unless (< n 1)
    (let ((result '()))
      (while (not (seq-empty-p sequence))
        (push (seq-take sequence n) result)
        (setq sequence (seq-drop sequence n)))
      (nreverse result))))