Skip to content
This repository
Browse code

Fixed `stream-add-between'.

Don't put an extra seperator element at the end of the stream.  Brings
it in-line with the list version (`add-between') and sequence
version (`sequence-add-between').  Includes a test.
  • Loading branch information...
commit 6e1ee717f77973976ddd50a63e1c77129d8ea0f7 1 parent 36dd749
MartyNeal authored April 19, 2012 elibarzilay committed May 04, 2012
15  collects/racket/stream.rkt
@@ -152,12 +152,15 @@
152 152
       (make-do-stream (lambda () (force!) empty?)
153 153
                       (lambda () (force!) fst)
154 154
                       (lambda () (force!) rst)))]))
155  
-  
  155
+
156 156
 (define (stream-add-between s e)
157 157
   (unless (stream? s)
158 158
     (raise-type-error 'stream-add-between "stream" s))
159  
-  (let loop ([s s])
160  
-    (cond
161  
-     [(stream-empty? s) empty-stream]
162  
-     [else (stream-cons (stream-first s)
163  
-                        (stream-cons e (loop (stream-rest s))))])))
  159
+  (if (stream-empty? s)
  160
+      empty-stream
  161
+      (stream-cons
  162
+       (stream-first s)
  163
+       (let loop ([s (stream-rest s)])
  164
+         (cond [(stream-empty? s) empty-stream]
  165
+               [else (stream-cons e (stream-cons (stream-first s)
  166
+                                                 (loop (stream-rest s))))])))))
3  collects/tests/racket/sequence.rktl
... ...
@@ -1,4 +1,3 @@
1  
-
2 1
 (load-relative "loadtest.rktl")
3 2
 
4 3
 (Section 'sequence)
@@ -108,6 +107,8 @@
108 107
         (sequence-ref (sequence-add-between (in-naturals) #t) 2))
109 108
   (test #t 'sequence-add-between
110 109
         (sequence-ref (sequence-add-between (in-naturals) #t) 3))
  110
+  (test 3 'sequence-add-between
  111
+        (sequence-length (sequence-add-between (in-range 2) #t)))
111 112
 
112 113
   (arity-test sequence-count 2 2)
113 114
   (test 0 'sequence-count (sequence-count even? empty-sequence))

0 notes on commit 6e1ee71

Please sign in to comment.
Something went wrong with that request. Please try again.