From 5a17028620ed7d940eb18ce7f4f552e12214ce12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 23 Mar 2020 01:04:37 +0100 Subject: Hopefully fixed events-between. --- module/srfi/srfi-41/util.scm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'module/srfi') diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm index 3101bc85..dda0fcd0 100644 --- a/module/srfi/srfi-41/util.scm +++ b/module/srfi/srfi-41/util.scm @@ -28,6 +28,10 @@ ;; on. From there it knows that once it has found the first element ;; that satisfies our predicate all remaining elements satisfying pred ;; will be in direct succession. +;; Does have some drawbacks, concider an event between 2020-01-01 and 2020-12-31. +;; The collection is sorted on start time, and we want all events overlapping the +;; interval 2020-02-01 to 2020-02-29. We would get the long event, but then probably +;; stop because all regular small events in january. (define-public (filter-sorted-stream pred stream) (stream-take-while pred (stream-drop-while @@ -48,6 +52,16 @@ [else (filter-sorted-stream* pred? keep-remaining? (stream-cdr stream))])) + +;; returns all object in stream from the first object satisfying +;; start-pred, until the last object which sattisfies end-pred. +(define-public (get-stream-interval start-pred end-pred stream) + (stream-take-while + end-pred (stream-drop-while + (negate start-pred) + stream))) + + ;; Finds the first element in stream satisfying pred. ;; Returns #f if nothing was found (define-public (stream-find pred stream) -- cgit v1.2.3