summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-10-31 23:14:34 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-10-31 23:14:34 +0100
commite822d10530fc291f722a628b430fa8f08eb9dd5d (patch)
treee3579b020b4a791e1c55e03e05c5dd8dae6a3209
parent86bb105de83830145be0f9b715499ef950f5c018 (diff)
downloadmew-e822d10530fc291f722a628b430fa8f08eb9dd5d.tar.gz
mew-e822d10530fc291f722a628b430fa8f08eb9dd5d.tar.xz
mew-e822d10530fc291f722a628b430fa8f08eb9dd5d.zip
add ggflatten
-rw-r--r--mew.scm18
-rw-r--r--mew.svnwiki4
2 files changed, 21 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm
index 1af0701..71bb99a 100644
--- a/mew.scm
+++ b/mew.scm
@@ -5,7 +5,8 @@
      dec def div
      empty? eof esc
      fin final for fun*
-     gen generic-for-each genumerate get gfix giterate gmatch group-by-accumulator gslice-when gsplit gwindow
+     gen generic-for-each genumerate get gfix ggflatten giterate gmatch
+     group-by-accumulator gslice-when gsplit gwindow
      inc inject into
      juxt
      keys
@@ -312,6 +313,21 @@
 
   (define (eof) #!eof)
 
+  (define (ggflatten gen)
+    (let ((gen2 #f))
+      (lambda ()
+        (unless gen2
+          (set! gen2 (gen)))
+        (let loop ()
+          (if (eof-object? gen2)
+            gen2
+            (let ((v (gen2)))
+              (if (eof-object? v)
+                (begin
+                  (set! gen2 (gen))
+                  (loop))
+                v)))))))
+
   (define (gwindow gen n)
     (let ((window #f))
       (lambda ()
diff --git a/mew.svnwiki b/mew.svnwiki
index a838550..8cad5c3 100644
--- a/mew.svnwiki
+++ b/mew.svnwiki
@@ -269,6 +269,10 @@ Alias for {{make-range-generator}}.
 
 Generator returning {{<val>}}, {{(<fun> <val>)}}, {{(<fun> (<fun (<val>)))}}...
 
+<procedure>(ggflatten <gen>)</procedure>
+
+Generator yielding all values of the all generators yielded by {{<gen>}}.
+
 <procedure>(gwindow <gen> <len>)</procedure>
 
 Generator yielding a sliding window of length {{<len>}} (as a list)