diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-10 13:32:04 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-10 13:32:04 +0200 |
commit | 430fa78d26a9077e6e462acae45a841912bb5bce (patch) | |
tree | 08c4444f96f0bb11ef5995498eb29b2ff6083127 /module/srfi/srfi-41/util.scm | |
parent | Add support for arrow keys in term. (diff) | |
parent | Add TODO:s to server. (diff) | |
download | calp-430fa78d26a9077e6e462acae45a841912bb5bce.tar.gz calp-430fa78d26a9077e6e462acae45a841912bb5bce.tar.xz |
Merge branch 'smalltime' into master
Diffstat (limited to 'module/srfi/srfi-41/util.scm')
-rw-r--r-- | module/srfi/srfi-41/util.scm | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm index 472170d7..51671985 100644 --- a/module/srfi/srfi-41/util.scm +++ b/module/srfi/srfi-41/util.scm @@ -1,8 +1,10 @@ (define-module (srfi srfi-41 util) #:use-module (srfi srfi-1) #:use-module (srfi srfi-41) + #:use-module ((ice-9 sandbox) :select (call-with-time-limit)) #:use-module (util) ; let*, find-min - #:export (stream-car+cdr interleave-streams with-streams)) + #:export (stream-car+cdr interleave-streams with-streams + stream-timeslice-limit)) (define (stream-car+cdr stream) (values (stream-car stream) @@ -102,6 +104,22 @@ (define*-public (stream-paginate stream optional: (page-size 10)) (stream-paginate% stream page-size)) + +;; stream cons, but eval arguments beforehand. +(define (eager-stream-cons a b) + (stream-cons a b)) + +;; Wrap a stream in time limits. Each element has at most @var{timeslice} +;; seconds to produce a value, otherwise the stream ends. Useful for finding the +;; "final" element matching a predicate in an infinite stream. +(define-stream (stream-timeslice-limit strm timeslice) + (call-with-time-limit + timeslice + (lambda () (eager-stream-cons + (stream-car strm) + (stream-timeslice-limit (stream-cdr strm) timeslice))) + (lambda _ stream-null))) + ;; 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 |