aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2018-12-18 09:42:50 +0100
committerNicolas Petton2018-12-18 09:42:50 +0100
commit5a9eba603d193324c7ff8c654fa28c6b4f3928f7 (patch)
treeda277418a4a17987e8ba30642de863f09b9f5bc1
parent73b2f7ac698601d3dfbedd7949d95bc506497c50 (diff)
downloademacs-5a9eba603d193324c7ff8c654fa28c6b4f3928f7.tar.gz
emacs-5a9eba603d193324c7ff8c654fa28c6b4f3928f7.zip
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.
-rw-r--r--lisp/emacs-lisp/seq.el10
-rw-r--r--test/lisp/emacs-lisp/seq-tests.el12
2 files changed, 21 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index b40c424e303..3da33dac4aa 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Nicolas Petton <nicolas@petton.fr> 5;; Author: Nicolas Petton <nicolas@petton.fr>
6;; Keywords: sequences 6;; Keywords: sequences
7;; Version: 2.20 7;; Version: 2.21
8;; Package: seq 8;; Package: seq
9 9
10;; Maintainer: emacs-devel@gnu.org 10;; Maintainer: emacs-devel@gnu.org
@@ -110,6 +110,14 @@ name to be bound to the rest of SEQUENCE."
110 "Return the number of elements of SEQUENCE." 110 "Return the number of elements of SEQUENCE."
111 (length sequence)) 111 (length sequence))
112 112
113(defun seq-first (sequence)
114 "Return the first element of SEQUENCE."
115 (seq-elt sequence 0))
116
117(defun seq-rest (sequence)
118 "Return a sequence of the elements of SEQUENCE except the first one."
119 (seq-drop sequence 1))
120
113(cl-defgeneric seq-do (function sequence) 121(cl-defgeneric seq-do (function sequence)
114 "Apply FUNCTION to each element of SEQUENCE, presumably for side effects. 122 "Apply FUNCTION to each element of SEQUENCE, presumably for side effects.
115Return SEQUENCE." 123Return SEQUENCE."
diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el
index 989ec3cf9e0..0f11bd9714c 100644
--- a/test/lisp/emacs-lisp/seq-tests.el
+++ b/test/lisp/emacs-lisp/seq-tests.el
@@ -424,5 +424,17 @@ Evaluate BODY for each created sequence.
424 (should (eq (seq-into vec 'vector) vec)) 424 (should (eq (seq-into vec 'vector) vec))
425 (should (eq (seq-into str 'string) str)))) 425 (should (eq (seq-into str 'string) str))))
426 426
427(ert-deftest test-seq-first ()
428 (let ((lst '(1 2 3))
429 (vec [1 2 3]))
430 (should (eq (seq-first lst) 1))
431 (should (eq (seq-first vec) 1))))
432
433(ert-deftest test-seq-rest ()
434 (let ((lst '(1 2 3))
435 (vec [1 2 3]))
436 (should (equal (seq-rest lst) '(2 3)))
437 (should (equal (seq-rest vec) [2 3]))))
438
427(provide 'seq-tests) 439(provide 'seq-tests)
428;;; seq-tests.el ends here 440;;; seq-tests.el ends here