[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 7d39453fd6 1/2: Add new predicate list-of-strings-p
From: |
Lars Ingebrigtsen |
Subject: |
master 7d39453fd6 1/2: Add new predicate list-of-strings-p |
Date: |
Fri, 16 Sep 2022 06:36:31 -0400 (EDT) |
branch: master
commit 7d39453fd64e355526291b0ca5672e838de5fb58
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Add new predicate list-of-strings-p
* lisp/subr.el (list-of-strings-p): New function.
---
lisp/subr.el | 5 +++++
test/lisp/subr-tests.el | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/lisp/subr.el b/lisp/subr.el
index bfc2e207b2..e8e8f1584b 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4026,6 +4026,11 @@ system's shell."
Otherwise, return nil."
(or (stringp object) (null object)))
+(defun list-of-strings-p (object)
+ "Return t if OBJECT is nil or a list of strings."
+ (and (listp object)
+ (seq-every-p #'stringp object)))
+
(defun booleanp (object)
"Return t if OBJECT is one of the two canonical boolean values: t or nil.
Otherwise, return nil."
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 3011713210..38966cea58 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -1158,5 +1158,12 @@ final or penultimate step during initialization."))
(should (equal (butlast l n)
(subr-tests--butlast-ref l n))))))
+(ert-deftest test-list-of-strings-p ()
+ (should-not (list-of-strings-p 1))
+ (should (list-of-strings-p nil))
+ (should (list-of-strings-p '("a" "b")))
+ (should-not (list-of-strings-p ["a" "b"]))
+ (should-not (list-of-strings-p '("a" nil "b"))))
+
(provide 'subr-tests)
;;; subr-tests.el ends here