From b6b177c9da2efee680ae3b0f45db66478e7324bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 24 May 2020 22:31:46 +0200 Subject: Add stream-partition. --- module/srfi/srfi-41/util.scm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'module') 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 -- cgit v1.2.3