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

Function slice() losing value after reach maximum index #75

Closed
bronek89 opened this issue Nov 29, 2018 · 1 comment
Closed

Function slice() losing value after reach maximum index #75

bronek89 opened this issue Nov 29, 2018 · 1 comment

Comments

@bronek89
Copy link
Contributor

bronek89 commented Nov 29, 2018

Hi,

I think that working of function slice is little broken right now.

Current implementation of slice function breaks iteration after fetching item from iterator that is outside of maximum index. It causes lost of last iteration element.

Consider example below:
https://3v4l.org/6B9QS

test 1 is original function
test 2 is changed function to break immediately after yielding last element

When you have a function like that:

$i = function () {
    for ($idx = 0; $idx < 1000; $idx ++) {
        echo "preprocess {$idx} \n";
        yield $idx;
    }
};

and do slice($i(), 0, 3);

Do you expect to "preprocess 3" will be executed or not?

I made PR to illustrate change that fixes described behaviuor: #76

Regards

@bronek89
Copy link
Contributor Author

Implemented in 956ff19 :)

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

No branches or pull requests

1 participant