1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 10:31:37 -08:00

New convenience functions in seq.el

Functions to access the first or all but the first elements of
sequences have been repeatedly asked for (the last occurrence being
https://github.com/NicolasPetton/seq.el/issues/9).

* lisp/emacs-lisp/seq.el (seq-first, seq-rest): New functions.
* test/lisp/emacs-lisp/seq-tests.el (test-seq-first, test-seq-rest):
New tests for seq-first and seq-rest.
This commit is contained in:
Nicolas Petton 2018-12-18 09:42:50 +01:00
parent 73b2f7ac69
commit 5a9eba603d
No known key found for this signature in database
GPG key ID: E8BCD7866AFCF978
2 changed files with 21 additions and 1 deletions

View file

@ -4,7 +4,7 @@
;; Author: Nicolas Petton <nicolas@petton.fr>
;; Keywords: sequences
;; Version: 2.20
;; Version: 2.21
;; Package: seq
;; Maintainer: emacs-devel@gnu.org
@ -110,6 +110,14 @@ name to be bound to the rest of SEQUENCE."
"Return the number of elements of SEQUENCE."
(length sequence))
(defun seq-first (sequence)
"Return the first element of SEQUENCE."
(seq-elt sequence 0))
(defun seq-rest (sequence)
"Return a sequence of the elements of SEQUENCE except the first one."
(seq-drop sequence 1))
(cl-defgeneric seq-do (function sequence)
"Apply FUNCTION to each element of SEQUENCE, presumably for side effects.
Return SEQUENCE."

View file

@ -424,5 +424,17 @@ Evaluate BODY for each created sequence.
(should (eq (seq-into vec 'vector) vec))
(should (eq (seq-into str 'string) str))))
(ert-deftest test-seq-first ()
(let ((lst '(1 2 3))
(vec [1 2 3]))
(should (eq (seq-first lst) 1))
(should (eq (seq-first vec) 1))))
(ert-deftest test-seq-rest ()
(let ((lst '(1 2 3))
(vec [1 2 3]))
(should (equal (seq-rest lst) '(2 3)))
(should (equal (seq-rest vec) [2 3]))))
(provide 'seq-tests)
;;; seq-tests.el ends here