# HG changeset patch # User Steve Losh # Date 1507872750 14400 # Node ID 1e90139a06b110eb5b8e7e86d2a89ef212cab6bb # Parent 8fe530a607d6d82557c219f085ddea1cc9952897 Add `hset-reduce` diff -r 8fe530a607d6 -r 1e90139a06b1 DOCUMENTATION.markdown --- a/DOCUMENTATION.markdown Wed Sep 27 20:03:21 2017 -0400 +++ b/DOCUMENTATION.markdown Fri Oct 13 01:32:30 2017 -0400 @@ -1193,6 +1193,16 @@ +### `HSET-REDUCE` (function) + + (HSET-REDUCE HSET FUNCTION &KEY (INITIAL-VALUE NIL IVP)) + +Reduce `function` over the elements of `hset`. + + The order in which the elements are processed is undefined. + + + ### `HSET-REMOVE!` (function) (HSET-REMOVE! HSET &REST ELEMENTS) diff -r 8fe530a607d6 -r 1e90139a06b1 losh.lisp --- a/losh.lisp Wed Sep 27 20:03:21 2017 -0400 +++ b/losh.lisp Fri Oct 13 01:32:30 2017 -0400 @@ -2749,6 +2749,18 @@ new)) +(define-hset-op hset-reduce (hset function &key (initial-value nil ivp)) + "Reduce `function` over the elements of `hset`. + + The order in which the elements are processed is undefined. + + " + (if ivp + (iterate (for (n nil) :in-hashtable storage) + (reducing n by function :initial-value initial-value)) + (iterate (for (n nil) :in-hashtable storage) + (reducing n by function)))) + (define-hset-op hset-elements (hset) "Return a fresh list containing the elements of `hset`." (hash-table-keys storage)) diff -r 8fe530a607d6 -r 1e90139a06b1 package.lisp --- a/package.lisp Wed Sep 27 20:03:21 2017 -0400 +++ b/package.lisp Fri Oct 13 01:32:30 2017 -0400 @@ -154,7 +154,7 @@ :hset-filter! :hset-map :hset-map! - )) + :hset-reduce)) (defpackage :losh.hash-tables (:documentation "Utilities for operating on hash tables.")