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

when.iterate bug #462

Open
ericmarkmartin opened this issue Jul 27, 2015 · 2 comments
Open

when.iterate bug #462

ericmarkmartin opened this issue Jul 27, 2015 · 2 comments

Comments

@ericmarkmartin
Copy link

According to the docs, the seed value passed to when.iterate is passed to the handler and then f. However, it is first passed to the predicate.

@briancavalier
Copy link
Member

Hey @ericmarkmartin, this seems like just unclear documentation rather than a bug in functionality. Thanks for reporting it.

@mnahkies
Copy link

mnahkies commented Sep 2, 2015

@briancavalier: I think the documentation is incorrect, rather than just unclear.

It gives this example:

// Logs
// 0
// 1
// 2
// ...
// 100000000000
when.iterate(function(x) {
    return x+1;
}, function(x) {
    // Stop when x >= 100000000000
    return x >= 100000000000;
}, function(x) {
    console.log(x);
}, 0).done();

However if you run this example, the output stops one item short of expected, eg: if the target was 5 you would get:

0
1
2
3
4

This occurs because the predicate is evaluated before the process function, and the process function is not called for the final value passed to the predicate function. ie: the value that the predicate returns true for.

I'm not sure which was the originally intended behaviour, but it would be great if one of the two was altered to make things consistent.

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

3 participants