1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

New function seq-sort-by in seq.el

* lisp/emacs-lisp/seq.el (seq-sort-by): New function.
* test/lisp/emacs-lisp/seq-tests.el: New test for seq-sort-by.
* doc/lispref/sequences.texi: Add documentation for seq-sort-by.
This commit is contained in:
Nicolas Petton 2016-03-29 09:19:32 +02:00
parent a30e7e12ed
commit 2946344a23
3 changed files with 28 additions and 1 deletions

View file

@ -4,7 +4,7 @@
;; Author: Nicolas Petton <nicolas@petton.fr>
;; Keywords: sequences
;; Version: 2.3
;; Version: 2.14
;; Package: seq
;; Maintainer: emacs-devel@gnu.org
@ -218,6 +218,16 @@ The result is a sequence of the same type as SEQUENCE."
(cl-defmethod seq-sort (pred (list list))
(sort (seq-copy list) pred))
(defun seq-sort-by (function pred sequence)
"Sort SEQUENCE using PRED as a comparison function.
Elements of SEQUENCE are transformed by FUNCTION before being
sorted. FUNCTION must be a function of one argument."
(seq-sort (lambda (a b)
(funcall pred
(funcall function a)
(funcall function b)))
sequence))
(cl-defgeneric seq-reverse (sequence)
"Return a sequence with elements of SEQUENCE in reverse order."
(let ((result '()))