Skip to content

add reuse warning about buffered iterators #501

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

Closed
wants to merge 1 commit into from

Conversation

brahn
Copy link

@brahn brahn commented Mar 7, 2016

The scaladocs for Iterators has a very useful warning on the method buffered:

Reuse: After calling this method, one should discard the iterator it was called on,
and use only the iterator that was returned. Using the old iterator is undefined,
subject to change, and may result in changes to the new iterator as well.

This PR adds that warning (along with some explanatory text) to the corresponding discussion on http://docs.scala-lang.org/overviews/collections/iterators.html#buffered-iterators

(I got bitten by looking at the latter without seeing the former.)

@SethTisue
Copy link
Member

a great many methods on Iterator have this issue; buffered isn't really special in this regard. what do you think about taking what you've done here and making the warning more general...?


// Incorrect
val it: Iterator[Int] = ...
myFunction(it.buffered.head, it)
Copy link
Contributor

Choose a reason for hiding this comment

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

in #551 I just reiterate, "don't re-use the original iterator", which is the theme of most of the page.

I also place an ad for Iterator.single(head) ++ rest. It makes me wonder if BufferedIterator.toIterator should do that; except that it doesn't have much overhead, which is another point I added.

@SethTisue
Copy link
Member

superseded by #551. thanks @brahn for calling it to the community's attention

@SethTisue SethTisue closed this Aug 8, 2016
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.

4 participants