Next: streams match, Previous: streams unfold, Up: streams [Index]
Apply a procedure element–wise to corresponding elements of the input streams, returning a newly–allocated stream containing elements that are the results of those procedure applications. The output stream has as many elements as the minimum–length input stream, and may be infinite.
(define (square x) (* x x)) (stream-map square (stream 9 3)) ⇒ 81 9 (define (sigma f m n) (stream-fold + 0 (stream-map f (stream-range m (+ n 1))))) (sigma square 1 100) ⇒ 338350
Apply a procedure element–wise to corresponding elements of the input
streams for its side–effects; return nothing.
stops as soon as any of its input streams is exhausted.
Example, the following procedure displays the contents of a file:
(define (display-file filename) (stream-for-each display (file->stream filename)))