From 9dc66f01d3116e663627c9e9f15a0de60035a246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 21 Mar 2019 02:37:54 +0100 Subject: Started work on stream interleaving. --- srfi/srfi-41/util.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 srfi/srfi-41/util.scm (limited to 'srfi') diff --git a/srfi/srfi-41/util.scm b/srfi/srfi-41/util.scm new file mode 100644 index 00000000..ed378ea4 --- /dev/null +++ b/srfi/srfi-41/util.scm @@ -0,0 +1,24 @@ +(define-module (srfi srfi-41 util) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-41) + #:use-module (util) ; let*, find-min + #:export (stream-car+cdr interleave-streams)) + +(define (stream-car+cdr stream) + (values (stream-car stream) + (stream-cdr stream))) + +;; Merges a number of totally ordered streams into a single +;; totally ordered stream. +;; ((≺, stream)) → (≺, stream) +(define (interleave-streams < streams) + ;; Drop all empty streams + (let ((streams (remove stream-null? streams))) + ;; If all streams where empty, end the output stream + (if (null? streams) + stream-null + (let* ((min other (find-min < stream-car streams)) + (m ms (stream-car+cdr min))) + (stream-cons m (interleave-streams < (cons ms other))))))) + +;;; Varför är allting så långsamt‽‽‽‽‽‽‽‽ -- cgit v1.2.3