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

Make slice() breaks immediately after last value #76

Closed
wants to merge 3 commits into from

Conversation

bronek89
Copy link
Contributor

See #75

@@ -487,13 +487,13 @@ function slice(iterable $iterable, int $start, $length = INF): \Iterator {

Copy link
Owner

Choose a reason for hiding this comment

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

We'll now need a check for zero length here and abort early in that case.

Copy link
Owner

Choose a reason for hiding this comment

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

Though that will also change behavior in that it will no longer consume the first $start elements of the iterator. Not sure if that's important...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added check for zero length.

And you are right - it will no longer run iterator in that case.
I don't know if that's ok or not. I've never used zero length for slicing.. (at least not intentionally)

src/iter.php Outdated Show resolved Hide resolved
@nikic
Copy link
Owner

nikic commented Mar 26, 2019

Merged as 956ff19. Sorry for the long delay!

@nikic nikic closed this Mar 26, 2019
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.

2 participants