Skip to content

Conversation

@Philippe-Cholet
Copy link
Member

Resolves #600. See #600 (comment) for why I don't see an alternative.

@Philippe-Cholet Philippe-Cholet added this to the next milestone Jan 11, 2024
Copy link
Member

@phimuemue phimuemue left a comment

Choose a reason for hiding this comment

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

I approve this, because having the docs is better than not having them.

But isn't the interesting part here that the "next next" value is computed in next? And: Doesn't successors potentially suffer the same problem (albeit able to circumvent it using None)? (see https://doc.rust-lang.org/beta/src/core/iter/sources/successors.rs.html#48)

@Philippe-Cholet
Copy link
Member Author

Philippe-Cholet commented Jan 11, 2024

Without Clone-able values, iterate and successors are forced to compute it ahead-of-time while we still have access to the value, it's the trade-off: not cloned but ahead-of-time computation. But being able to return None in successors' closure seems a better API decision to me.

EDIT: Not being able to stop the iterator with None kinda suppose it can continue forever (Iterate::size_hint explicitly says it).

The working example of iterate seems more like a successors example to me.
iterate(1, |n| (n + 1) % 3) would be appropriate to me.

... It lead me to change the working example to better describe iterate vs successors.
It could be something different than basically (1..=3).cycle() though.

@Philippe-Cholet Philippe-Cholet added this pull request to the merge queue Jan 12, 2024
Merged via the queue into rust-itertools:master with commit 62bbd2f Jan 12, 2024
@Philippe-Cholet Philippe-Cholet deleted the beware-iterate branch January 12, 2024 07:40
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.

Iterate advances the source iterator one element ahead

2 participants