Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 MartyNeal authored elibarzilay committed
Showing with 11 additions and 7 deletions.
  1. +9 −6 collects/racket/stream.rkt
  2. +2 −1  collects/tests/racket/sequence.rktl
View
15 collects/racket/stream.rkt
@@ -152,12 +152,15 @@
(make-do-stream (lambda () (force!) empty?)
(lambda () (force!) fst)
(lambda () (force!) rst)))]))
-
+
(define (stream-add-between s e)
(unless (stream? s)
(raise-type-error 'stream-add-between "stream" s))
- (let loop ([s s])
- (cond
- [(stream-empty? s) empty-stream]
- [else (stream-cons (stream-first s)
- (stream-cons e (loop (stream-rest s))))])))
+ (if (stream-empty? s)
+ empty-stream
+ (stream-cons
+ (stream-first s)
+ (let loop ([s (stream-rest s)])
+ (cond [(stream-empty? s) empty-stream]
+ [else (stream-cons e (stream-cons (stream-first s)
+ (loop (stream-rest s))))])))))
View
3  collects/tests/racket/sequence.rktl
@@ -1,4 +1,3 @@
-
(load-relative "loadtest.rktl")
(Section 'sequence)
@@ -108,6 +107,8 @@
(sequence-ref (sequence-add-between (in-naturals) #t) 2))
(test #t 'sequence-add-between
(sequence-ref (sequence-add-between (in-naturals) #t) 3))
+ (test 3 'sequence-add-between
+ (sequence-length (sequence-add-between (in-range 2) #t)))
(arity-test sequence-count 2 2)
(test 0 'sequence-count (sequence-count even? empty-sequence))
Please sign in to comment.
Something went wrong with that request. Please try again.