summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorNicolas Petton <nicolas@petton.fr>2018-12-18 09:42:50 +0100
committerNicolas Petton <nicolas@petton.fr>2018-12-18 09:42:50 +0100
commit5a9eba603d193324c7ff8c654fa28c6b4f3928f7 (patch)
treeda277418a4a17987e8ba30642de863f09b9f5bc1 /lisp/emacs-lisp
parent73b2f7ac698601d3dfbedd7949d95bc506497c50 (diff)
downloademacs-5a9eba603d193324c7ff8c654fa28c6b4f3928f7.tar.gz
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.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/seq.el10
1 files changed, 9 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 @@
;; 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."