diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-09-11 17:54:35 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-09-11 19:58:54 +0200 |
commit | 634502e7246f8850ad6c649b79ae9f072f45baf4 (patch) | |
tree | 56ee3154fbd08ea175ef141fbf8c22407ec5ca83 /module/srfi/srfi-41/util.scm | |
parent | Change how entry point is handled. (diff) | |
download | calp-634502e7246f8850ad6c649b79ae9f072f45baf4.tar.gz calp-634502e7246f8850ad6c649b79ae9f072f45baf4.tar.xz |
Introduce stream-split-by.
This procedure isn't currently used, but as noted is really useful for
grouping a character stream into a word stream, which is a later commit
will use for it for justifying posibly infinite streams of text.
Diffstat (limited to 'module/srfi/srfi-41/util.scm')
-rw-r--r-- | module/srfi/srfi-41/util.scm | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm index cecbb3b3..1571cc4c 100644 --- a/module/srfi/srfi-41/util.scm +++ b/module/srfi/srfi-41/util.scm @@ -18,7 +18,8 @@ stream-partition stream-split stream-paginate - stream-timeslice-limit)) + stream-timeslice-limit + stream-split-by)) (define (stream-car+cdr stream) (values (stream-car stream) @@ -146,3 +147,15 @@ (stream-timeslice-limit (stream-cdr strm) timeslice))) (lambda _ stream-null))) + +(define-stream (stream-split-by pred strm) + (let loop ((accumulated '()) + (strm strm)) + (stream-match strm + (() (if (null? accumulated) + stream-null + (stream (reverse accumulated)))) + ((x . xs) (pred x) + (stream-cons (reverse (cons x accumulated)) (loop '() xs))) + ((x . xs) + (loop (cons x accumulated) xs))))) |