aboutsummaryrefslogtreecommitdiff
path: root/module/srfi
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-05-24 22:31:46 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-05-24 22:31:46 +0200
commitb6b177c9da2efee680ae3b0f45db66478e7324bc (patch)
treecc0ec26994788f6710461006fbe1a51344102479 /module/srfi
parentAdd comment about allows multi-valued items in ics. (diff)
downloadcalp-b6b177c9da2efee680ae3b0f45db66478e7324bc.tar.gz
calp-b6b177c9da2efee680ae3b0f45db66478e7324bc.tar.xz
Add stream-partition.
Diffstat (limited to 'module/srfi')
-rw-r--r--module/srfi/srfi-41/util.scm11
1 files changed, 11 insertions, 0 deletions
diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm
index 0aa4ae9a..629f3242 100644
--- a/module/srfi/srfi-41/util.scm
+++ b/module/srfi/srfi-41/util.scm
@@ -75,6 +75,17 @@
(define-public (stream->values stream)
(apply values (stream->list stream)))
+;; Returns two values. A steam of all the elements in stream
+;; which satisfiy @var{pred}, and a stream of those elements
+;; that don't. @var{pred} is called once per value in the
+;; input stream.
+(define-public (stream-partition pred stream)
+ (let ((strm (stream-zip (stream-map pred stream)
+ stream)))
+ (values
+ (stream-map cadr (stream-filter car strm))
+ (stream-map cadr (stream-remove car strm)))))
+
;; Evaluates @var{body} in a context where most list fundamentals are
;; replaced by stream alternatives.
;; commented defifinitions are items which could be included, but for