emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 1d471c80f6 2/2: compat-25: Add hash-table-empty-


From: ELPA Syncer
Subject: [elpa] externals/compat 1d471c80f6 2/2: compat-25: Add hash-table-empty-p
Date: Tue, 17 Jan 2023 05:57:31 -0500 (EST)

branch: externals/compat
commit 1d471c80f6527a2719346d68375392273cbe46ca
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-25: Add hash-table-empty-p
---
 NEWS.org        | 1 +
 compat-25.el    | 4 ++++
 compat-tests.el | 6 ++++++
 compat.texi     | 5 +++++
 4 files changed, 16 insertions(+)

diff --git a/NEWS.org b/NEWS.org
index 9452ecf8d6..1b26dcd91d 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -2,6 +2,7 @@
 
 * Development
 
+- compat-25: Add ~hash-table-empty-p~.
 - compat-27: Add ~date-ordinal-to-time~.
 - compat-27: Add ~make-decoded-time~.
 - compat-28: Add ~color-dark-p~.
diff --git a/compat-25.el b/compat-25.el
index ebeee09fab..d12d09fc38 100644
--- a/compat-25.el
+++ b/compat-25.el
@@ -145,6 +145,10 @@ The variable list SPEC is the same as in `if-let'."
 
 ;;;; Defined in subr-x.el
 
+(compat-defun hash-table-empty-p (hash-table) ;; 
<compat-tests:hash-table-empty-p>
+  "Check whether HASH-TABLE is empty (has 0 elements)."
+  (zerop (hash-table-count hash-table)))
+
 (compat-defmacro thread-first (&rest forms) ;; <compat-tests:thread-first>
   "Thread FORMS elements as the first argument of their successor.
 Example:
diff --git a/compat-tests.el b/compat-tests.el
index cad2b45c29..2ae8fc67ed 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -818,6 +818,12 @@
   (should-error (ignore-error foo
                   (read ""))))
 
+(ert-deftest hash-table-empty-p ()
+  (should (hash-table-empty-p (make-hash-table)))
+  (let ((ht (make-hash-table)))
+    (puthash 'k 'v ht)
+    (should-not (hash-table-empty-p ht))))
+
 (ert-deftest thread-first ()
   (should-equal (thread-first (+ 40 2)) 42)
   (should-equal (thread-first
diff --git a/compat.texi b/compat.texi
index 353de31b06..8009d7aa46 100644
--- a/compat.texi
+++ b/compat.texi
@@ -331,6 +331,11 @@ As with @code{when}, if one is only interested in the case 
where all
 just as they are by @code{if-let*}.
 @end defmac
 
+@c based on lisp/subr-x.el
+@defun hash-table-empty hash-table
+Check whether @var{hash-table} is empty (has 0 elements).
+@end defun
+
 @c based on lisp/subr-x.el
 @defmac thread-first &rest forms
 Combine @var{forms} into a single expression by ``threading'' each



reply via email to

[Prev in Thread] Current Thread [Next in Thread]