diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-11-07 22:48:10 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-11-07 22:48:10 +0100 |
commit | 8972b21868d475a6a54c9719e6dd8167d5827ce6 (patch) | |
tree | 7ae18d45dee0bf9a38ac7466c8bcd98beb82f474 | |
parent | 0afc4e827e4c4a7076b1d65fa9290c36a937d607 (diff) | |
download | mew-8972b21868d475a6a54c9719e6dd8167d5827ce6.tar.gz mew-8972b21868d475a6a54c9719e6dd8167d5827ce6.tar.xz mew-8972b21868d475a6a54c9719e6dd8167d5827ce6.zip |
add gpick
-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 |