From 7d39453fd64e355526291b0ca5672e838de5fb58 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 16 Sep 2022 12:29:54 +0200 Subject: [PATCH] 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 bfc2e207b2c..e8e8f1584b4 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 30117132101..38966cea585 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 -- 2.39.2