(library (sph storage dg stream) (export dg-node-selection->element-stream dg-node-selection->stream dg-relation-selection->element-stream dg-relation-selection->stream dg-selection->element-stream dg-selection->stream dg-selection-stream->element-stream) (import (sph) (sph storage dg) (srfi srfi-41)) (define-stream (dg-selection->stream a reader read-count) "procedure dg-selection -> srfi-41-stream a stream of results from calling reader repeatedly" (stream-let next ((r (reader a read-count))) (if (null? r) stream-null (stream-cons r (next (reader a read-count)))))) (define-stream (dg-selection->element-stream a reader read-count) "procedure dg-selection -> srfi-41-stream a stream of merged results from calling reader repeatedly. note that readers like dg-relation-read have a count parameter and can return multiple elements at once. this procedure merges any multiple results as if it were a stream of single elements" (stream-let next ((r (reader a read-count))) (if (null? r) stream-null (stream-append (list->stream r) (next (reader a read-count)))))) (define-stream (dg-selection-stream->element-stream a) "dg-selection -> srfi-41-stream creates a stream of single records instead of dg-read results which are lists and contain \"read-count\" elements" (stream-let next ((rest a)) (if (stream-null? rest) stream-null (stream-append (list->stream (stream-car rest)) (next (stream-cdr rest)))))) (define (dg-relation-selection->stream a read-count) (dg-selection->stream a dg-relation-read read-count)) (define (dg-relation-selection->element-stream a read-count) (dg-selection->element-stream a dg-relation-read read-count)) (define (dg-node-selection->stream a read-count) (dg-selection->stream a dg-node-read read-count)) (define (dg-node-selection->element-stream a read-count) (dg-selection->element-stream a dg-node-read read-count)))