diff options
-rw-r--r-- | mew.scm | 12 | ||||
-rw-r--r-- | mew.svnwiki | 6 | ||||
-rw-r--r-- | tests/test.mew | 5 |
3 files changed, 22 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm index 05af49b..a56d4ec 100644 --- a/mew.scm +++ b/mew.scm @@ -7,7 +7,7 @@ empty? eof esc fin final for fun* gconcatenate gen generic-for-each genumerate get gfix giterate gmatch - group-by-accumulator gslice-when gsplit gwindow + gpick group-by-accumulator gslice-when gsplit gwindow inc inject into juxt keys @@ -403,6 +403,16 @@ (loop)) v))))))) + (define (gpick f gen) + (lambda () + (let loop ((item (gen))) + (if (eof-object? item) + item + (let ((v (f item))) + (if (eof-object? v) + (loop (gen)) + v)))))) + (define (gwindow gen n) (let ((window #f)) (lambda () diff --git a/mew.svnwiki b/mew.svnwiki index 18ae072..6a8432f 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -343,6 +343,12 @@ Generator returning {{<val>}}, {{(<fun> <val>)}}, {{(<fun> (<fun (<val>)))}}... Generator yielding all values of the all generators yielded by {{<gen>}}. +<procedure>(gpick <function> <gen>)<procedure> + +Like {{gmap}}, apply {{<function>}} to all values yielded by +the generator {{<gen>}}, but skip values when {{<function>}} returns +an eof object. + <procedure>(gwindow <gen> <len>)</procedure> Generator yielding a sliding window of length {{<len>}} (as a list) diff --git a/tests/test.mew b/tests/test.mew index c8c9d16..903620c 100644 --- a/tests/test.mew +++ b/tests/test.mew @@ -328,6 +328,11 @@ ; gconcatenate +(test-group "gpick" + (test '(2 4 6) (into '() (gpick (fun (x) (if (even? x) x (eof))) + (generator 1 2 3 4 5 6)))) + (test '(0 "" #f ()) (into '() (gpick (op) (generator 0 "" #f '()))))) + ; gwindow ; gslice-when |