File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 2525 习题完成情况:
2626 - 章节一: 43/46
2727 - 章节二: 88/97
28- - 章节三: 49 /82
28+ - 章节三: 50 /82
2929 - 章节四: TODO
3030 - 章节五: TODO
3131* 运行
Original file line number Diff line number Diff line change 1+ #lang racket
2+ (require "stream.rkt " )
3+
4+ (define (stream-map proc . argstreams)
5+ (if (stream-null? (car argstreams))
6+ the-empty-stream
7+ (cons-stream
8+ (apply proc (map stream-car argstreams))
9+ (apply stream-map
10+ (cons proc (map stream-cdr argstreams))))))
11+
12+ (module+ test
13+ (require rackunit)
14+
15+ (test-case "Test for two streams mapping "
16+ (define s1 (list-to-stream '(1 2 3 4 )))
17+ (define s2 (list-to-stream '(10 20 30 40 )))
18+ (define added (stream-map + s1 s2))
19+ (check-equal? (stream-to-list added 4 ) '(11 22 33 44 ))
20+ )
21+
22+ (test-case "Test for different length streams(stop at shortest) "
23+ (define s1 (list-to-stream '(1 2 )))
24+ (define s2 (list-to-stream '(10 20 30 40 )))
25+ (define added (stream-map + s1 s2))
26+ (check-equal? (stream-to-list added 4 ) '(11 22 ))
27+ )
28+ )
You can’t perform that action at this time.
0 commit comments