Function: seq-sort-by

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

Signature

(seq-sort-by FUNCTION PRED SEQUENCE)

Documentation

Sort SEQUENCE transformed by FUNCTION using PRED as the comparison function.

Elements of SEQUENCE are transformed by FUNCTION before being sorted. FUNCTION must be a function of one argument. The sort operates on a copy of SEQUENCE and does not modify SEQUENCE.

Other relevant functions are documented in the sequence group.

View in manual

Shortdoc

;; sequence
(seq-sort-by (lambda (a) (/ 1.0 a)) #'< '(1 2 3))
    => (3 2 1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/seq.el.gz
;;;###autoload
(defun seq-sort-by (function pred sequence)
  "Sort SEQUENCE transformed by FUNCTION using PRED as the comparison function.
Elements of SEQUENCE are transformed by FUNCTION before being
sorted.  FUNCTION must be a function of one argument.  The sort
operates on a copy of SEQUENCE and does not modify SEQUENCE."
  (seq-sort (lambda (a b)
              (funcall pred
                       (funcall function a)
                       (funcall function b)))
            sequence))