summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-10-31 23:12:31 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-10-31 23:12:31 +0100
commit78ec49d84418aa10c25cc418a8818518b6fa307f (patch)
tree8b9298c3fdd547c7bd045440309036a5799a2bfe
parent7f98ae1710bfd34d9111f8e8d7e6b358590fec3a (diff)
downloadmew-78ec49d84418aa10c25cc418a8818518b6fa307f.tar.gz
mew-78ec49d84418aa10c25cc418a8818518b6fa307f.tar.xz
mew-78ec49d84418aa10c25cc418a8818518b6fa307f.zip
add uniq-accumulator
-rw-r--r--mew.scm11
-rw-r--r--mew.svnwiki6
2 files changed, 16 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm
index edb14bc..bab917c 100644
--- a/mew.scm
+++ b/mew.scm
@@ -18,7 +18,7 @@
      sing? set str slurp
      tally-accumulator tbl time
      while
-     unlist until
+     uniq-accumulator unlist until
      vals
      -> fun-> fun->> set->
      <>?
@@ -611,6 +611,15 @@
             groups
             (hash-table-update!/default groups (f x) (op cons x _) '())))))
 
+  (define uniq-accumulator
+    (case-lambda
+      (() (uniq-accumulator (op)))
+      ((f) (let ((items (tbl)))
+             (lambda (x)
+               (if (eof-object? x)
+                 (hash-table-values items)
+                 (hash-table-update!/default items (f x) identity x)))))))
+
   (define-syntax one-of
     (er-macro-transformer
      (lambda (expr rename compare)
diff --git a/mew.svnwiki b/mew.svnwiki
index 9a75f5b..2829c5b 100644
--- a/mew.svnwiki
+++ b/mew.svnwiki
@@ -316,6 +316,12 @@ numbers.
 Returns an accumulator that stores all elements in lists in a hash-table,
 applying {{<f>}} to the element to compute the key.
 
+<procedure>(uniq-accumulator <f>?)</procedure>
+
+Returns an accumulator that returns a list of unique elements.
+Two elements are considered equal if their image under {{<f>}} is {{equal?}}.
+{{<f>}} defaults to the identity function.
+
 <procedure>(inject <f> <init>?)</procedure>
 
 Returns a procedure that takes an generator (or something convertible