Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Change repeatN to support n=0 #3492

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2574,9 +2574,9 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
* }}}
*/
def repeatN(n: Long): Stream[F, O] = {
require(n > 0, "n must be > 0") // same behaviour as sliding
if (n > 1) this ++ repeatN(n - 1)
else this
require(n >= 0, "n must be >= 0")
if (n > 0) this ++ repeatN(n - 1)
else Stream.empty
}

/** Converts a `Stream[F,Either[Throwable,O]]` to a `Stream[F,O]`, which emits right values and fails upon the first `Left(t)`.
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/test/scala/fs2/StreamSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class StreamSuite extends Fs2Suite {

property("repeatN") {
forAll(
Gen.chooseNum(1, 200),
Gen.chooseNum(0, 200),
Gen.chooseNum(1, 200).flatMap(i => Gen.listOfN(i, arbitrary[Int]))
) { (n: Int, testValues: List[Int]) =>
assertEquals(
Expand Down