Skip to content

Commit

Permalink
EphemeralStream#zip crashed on unequal lengths; fix & test.
Browse files Browse the repository at this point in the history
  • Loading branch information
S11001001 committed Aug 23, 2013
1 parent 07fea2e commit ab4e4b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/scalaz/EphemeralStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ sealed abstract class EphemeralStream[A] {
}

def zip[B](b: => EphemeralStream[B]): EphemeralStream[(A, B)] =
if(isEmpty && b.isEmpty)
if(isEmpty || b.isEmpty)
emptyEphemeralStream
else
cons((head(), b.head()), tail() zip b.tail())
Expand Down
8 changes: 8 additions & 0 deletions tests/src/test/scala/scalaz/EphemeralStreamTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ class EphemeralStreamTest extends Spec {
"foldLeft" ! prop{ xs: List[List[Int]] =>
Foldable[EphemeralStream].foldLeft(EphemeralStream(xs: _*), List[Int]())(_ ::: _) must be_===(xs.foldLeft(List[Int]())(_ ::: _))
}

"zip has right length" ! prop {(xs: EphemeralStream[Int], ys: EphemeralStream[Int]) =>
(xs zip ys).length must be_===(xs.length min ys.length)
}

"interleave has right length" ! prop {(xs: EphemeralStream[Int], ys: EphemeralStream[Int]) =>
(xs interleave ys).length must be_===(xs.length + ys.length)
}
}

0 comments on commit ab4e4b6

Please sign in to comment.