Function: seq-group-by

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

Signature

(seq-group-by FUNCTION SEQUENCE)

Documentation

Apply FUNCTION to each element of SEQUENCE.

Separate the elements of SEQUENCE into an alist using the results as keys. Keys are compared using equal.

Other relevant functions are documented in the sequence group.

View in manual

Shortdoc

;; sequence
(seq-group-by #'natnump '(-1 2 3 -4 -5 6))
    => ((nil -1 -4 -5) (t 2 3 6))

Implementations

(seq-group-by FUNCTION SEQUENCE) in `seq.el'.

Undocumented

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/seq.el.gz
;;;###autoload
(cl-defgeneric seq-group-by (function sequence)
  "Apply FUNCTION to each element of SEQUENCE.
Separate the elements of SEQUENCE into an alist using the results as
keys.  Keys are compared using `equal'."
  (seq-reduce
   (lambda (acc elt)
     (let* ((key (funcall function elt))
            (cell (assoc key acc)))
       (if cell
           (setcdr cell (push elt (cdr cell)))
         (push (list key elt) acc))
       acc))
   (seq-reverse sequence)
   nil))