Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change repeatN to support n=0 #3492

Merged
merged 1 commit into from
Oct 11, 2024
Merged

Change repeatN to support n=0 #3492

merged 1 commit into from
Oct 11, 2024

Conversation

L7R7
Copy link
Contributor

@L7R7 L7R7 commented Oct 11, 2024

While putting together a couple of simple Stream example, I was surprised that repeatN(0) fails with an error instead of completing with an empty Stream. I would have expected it to work as repeat.take(0) would do.

I'm opening this PR to get some feedback about this proposal. I'm happy to discuss possible consequences of this change.

Apart from avoiding surprises or confusion on the user side, I don't have any real use cases in mind where this would be necessary to have

Comment on lines 2579 to 2580
else if (n == 0) Stream.empty
else this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we know from the require, the only case not covered in the if(n > 0) is exactly 0, so maybe simplify to

Suggested change
else if (n == 0) Stream.empty
else this
else Stream.empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, absolutely! I'll amend my commit

This combinator now works equivalently to repeat.take(n)
@mpilquist mpilquist merged commit e54be00 into typelevel:main Oct 11, 2024
15 checks passed
@L7R7 L7R7 deleted the repeatN-zero branch October 11, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants