aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2026-03-21 09:37:07 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2026-03-21 09:37:07 +0100
commited148b6824df9045670cbc837edc5f6dec05813f (patch)
tree2fb61a634fbd0c3efeee6090121f5b411cf74810
parent7aae30b09eca26e53bb7215dc8c3ef193966b98a (diff)
compat-31: Rename any to member-if, keep alias
-rw-r--r--NEWS.org2
-rw-r--r--compat-31.el4
-rw-r--r--compat-tests.el25
3 files changed, 17 insertions, 14 deletions
diff --git a/NEWS.org b/NEWS.org
index c5c8b50..bc0fc46 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -16,7 +16,7 @@
- compat-31: New extended function =seconds-to-string=.
- compat-31: New function =hash-table-contains-p=.
- compat-31: New function =remove-display-text-property=.
-- compat-31: New functions =drop-while=, =take-while=, =any=, =all=.
+- compat-31: New functions =drop-while=, =take-while=, =member-if=, =any=, =all=.
- Drop support for Emacs 24.x. Emacs 25.1 is required now. In case
Emacs 24.x support is still needed, Compat 30 can be used.
diff --git a/compat-31.el b/compat-31.el
index adf9672..1e4f24f 100644
--- a/compat-31.el
+++ b/compat-31.el
@@ -47,12 +47,14 @@
"Non-nil if PRED is true for all elements in LIST."
(not (drop-while pred list)))
-(compat-defun any (pred list) ;; <compat-tests:any>
+(compat-defun member-if (pred list) ;; <compat-tests:member-if>
"Non-nil if PRED is true for at least one element in LIST.
Returns the LIST suffix starting at the first element that satisfies PRED,
or nil if none does."
(drop-while (lambda (x) (not (funcall pred x))) list))
+(compat-defalias any member-if) ;; <compat-tests:member-if>
+
(compat-defun hash-table-contains-p (key table) ;; <compat-tests:hash-table-contains-p>
"Return non-nil if TABLE has an element with KEY."
(declare (side-effect-free t))
diff --git a/compat-tests.el b/compat-tests.el
index 2df3f96..241149d 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -3079,20 +3079,21 @@
(should (equal (funcall (identity #'all) #'plusp ls) nil))
(should (equal (funcall (identity #'all) #'numberp ls) t))))
-(ert-deftest compat-any ()
- (should (equal (any #'hash-table-p nil) nil))
+(ert-deftest compat-member-if ()
+ (should (equal (member-if #'hash-table-p nil) nil))
(let ((ls (append '(3 2 1) '(0) '(-1 -2 -3))))
- (should (equal (any #'numberp ls) ls))
- (should (equal (any (lambda (x) (numberp x)) ls) ls))
- (should (equal (any #'plusp ls) ls))
- (should (equal (any #'zerop ls) '(0 -1 -2 -3)))
- (should (equal (any #'bufferp ls) nil))
+ (should (equal (member-if #'numberp ls) ls))
+ (should (equal (member-if (lambda (x) (numberp x)) ls) ls))
+ (should (equal (member-if #'plusp ls) ls))
+ (should (equal (member-if #'zerop ls) '(0 -1 -2 -3)))
+ (should (equal (member-if #'bufferp ls) nil))
(let ((z 9))
- (should (equal (any (lambda (x) (< x z)) ls) ls))
- (should (equal (any (lambda (x) (< x (- z 9))) ls) '(-1 -2 -3)))
- (should (equal (any (lambda (x) (> x z)) ls) nil)))
- (should (equal (funcall (identity #'any) #'minusp ls) '(-1 -2 -3)))
- (should (equal (funcall (identity #'any) #'stringp ls) nil))))
+ (should (equal (member-if (lambda (x) (< x z)) ls) ls))
+ (should (equal (member-if (lambda (x) (< x (- z 9))) ls) '(-1 -2 -3)))
+ (should (equal (member-if (lambda (x) (> x z)) ls) nil)))
+ (dolist (fun '(member-if any))
+ (should (equal (funcall (identity fun) #'minusp ls) '(-1 -2 -3)))
+ (should (equal (funcall (identity fun) #'stringp ls) nil)))))
(ert-deftest compat-hash-table-contains-p ()
(let ((h (make-hash-table :test #'equal)))