[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 5a9eba6: New convenience functions in seq.el
From: |
Nicolas Petton |
Subject: |
[Emacs-diffs] master 5a9eba6: New convenience functions in seq.el |
Date: |
Tue, 18 Dec 2018 03:45:47 -0500 (EST) |
branch: master
commit 5a9eba603d193324c7ff8c654fa28c6b4f3928f7
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>
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.
---
lisp/emacs-lisp/seq.el | 10 +++++++++-
test/lisp/emacs-lisp/seq-tests.el | 12 ++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index b40c424..3da33da 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
;; Author: Nicolas Petton <address@hidden>
;; Keywords: sequences
-;; Version: 2.20
+;; Version: 2.21
;; Package: seq
;; Maintainer: address@hidden
@@ -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."
diff --git a/test/lisp/emacs-lisp/seq-tests.el
b/test/lisp/emacs-lisp/seq-tests.el
index 989ec3c..0f11bd9 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.
(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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 5a9eba6: New convenience functions in seq.el,
Nicolas Petton <=