--- a/DOCUMENTATION.markdown Wed Feb 08 20:42:24 2023 -0500
+++ b/DOCUMENTATION.markdown Wed Feb 08 21:27:09 2023 -0500
@@ -1327,6 +1327,14 @@
+### `DO-HASH-SET` (macro)
+
+ (DO-HASH-SET (SYMBOL HSET)
+ &BODY
+ BODY)
+
+Iterate over `hset` with `symbol` bound to successive elements.
+
### `HASH-SET` (struct)
Slots: `STORAGE`
--- a/src/hash-sets.lisp Wed Feb 08 20:42:24 2023 -0500
+++ b/src/hash-sets.lisp Wed Feb 08 21:27:09 2023 -0500
@@ -229,3 +229,10 @@
(alexandria:hash-table-keys storage))
+(defmacro do-hash-set ((symbol hset) &body body)
+ "Iterate over `hset` with `symbol` bound to successive elements."
+ (with-gensyms (iter found)
+ `(with-hash-table-iterator (,iter (hash-set-storage ,hset))
+ (loop (multiple-value-bind (,found ,symbol) (,iter)
+ (unless ,found (return nil))
+ ,@body)))))
--- a/src/package.lisp Wed Feb 08 20:42:24 2023 -0500
+++ b/src/package.lisp Wed Feb 08 21:27:09 2023 -0500
@@ -96,7 +96,9 @@
:hset-filter!
:hset-map
:hset-map!
- :hset-reduce))
+ :hset-reduce
+
+ :do-hash-set))
(defpackage :losh.io