chickadee » sicp » stream-filter

stream-filter pred streamprocedure

Filters a stream, applying pred.

pred
The predicate upon which to filter.
stream
The stream to filter
(define (stream-filter pred stream)
  (cond ((stream-null? stream) stream-null)
        ((pred (stream-car stream))
         (cons-stream
           (stream-car stream)
           (stream-filter pred (stream-cdr stream))))
        (else (stream-filter pred (stream-cdr stream)))))