From d00fea566004e67161ee45246b239fff5d416b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 21 Dec 2021 16:17:28 +0100 Subject: Cleanup modules. Primarly this moves all vcompenent input and output code to clearly labeled modules, instead of being spread out. At the same time it also removes a handfull of unused procedures. --- module/vcomponent/util/group.scm | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 module/vcomponent/util/group.scm (limited to 'module/vcomponent/util/group.scm') diff --git a/module/vcomponent/util/group.scm b/module/vcomponent/util/group.scm new file mode 100644 index 00000000..f328cd18 --- /dev/null +++ b/module/vcomponent/util/group.scm @@ -0,0 +1,71 @@ +(define-module (vcomponent util group) + #:use-module (vcomponent) + #:use-module (vcomponent datetime) + #:use-module (datetime) + #:use-module (srfi srfi-41) + #:use-module (srfi srfi-41 util) + #:export (group-stream get-groups-between)) + +;; TODO templetize this +(define-stream (group-stream in-stream) + (define (ein? day) (lambda (e) (event-contains? e day))) + + (if (stream-null? in-stream) + stream-null + (let loop ((days (day-stream (as-date (prop (stream-car in-stream) 'DTSTART)))) + (stream in-stream)) + (let* ((day (stream-car days)) + (tomorow (stream-car (stream-cdr days)))) + + (let ((head (stream-take-while (ein? day) stream)) + (tail + ;; This is a filter, instead of a stream-span together with head, + ;; since events can span multiple days. + ;; This starts with taking everything which end after the beginning + ;; of tommorow, and finishes with the rest when it finds the first + ;; object which begins tomorow (after midnight, exclusize). + (filter-sorted-stream* + (lambda (e) (date/-timestream + (map (lambda (d) (cons d stream-null)) + (date-range start-date end-date)))] + [(car (stream-car good-part)) + (lambda (d) (date< start-date d)) + => (lambda (d) + (stream-append + (list->stream + (map (lambda (d) (cons d stream-null)) + (date-range start-date + (date- d (date day: 1))))) + good-part))] + [else good-part])) + + +(define-public (group->event-list group) + (stream->list (cdr group))) -- cgit v1.2.3