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

Unexpected/inconsistent behavior with IndexedSeq.iterator.take #5002

Closed
scabug opened this issue Sep 17, 2011 · 2 comments
Closed

Unexpected/inconsistent behavior with IndexedSeq.iterator.take #5002

scabug opened this issue Sep 17, 2011 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 17, 2011

I'm not sure whether this is a bug or just changing unspecified behavior in an iterator, but it caused some subtle breakage in some of my
software.

In 2.8:

{ val x = 1 to 10 toIndexedSeq; val y = x.iterator; println(y.take(200).toList); println(y.toList) }
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
List()

In 2.9.*:

{ val x = 1 to 10 toIndexedSeq; val y = x.iterator; println(y.take(200).toList); println(y.toList) }
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

and for comparison, changing toIndexedSeq to toList in 2.9:

{ val x = 1 to 10 toList; val y = x.iterator; println(y.take(200).toList); println(y.toList) }
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
List()

Is it just the case that we're not supposed to ever use the old iterator again, after calling an iterator-producing method on an iterator, because the behavior is unspecified? Or is this unintended breakage in the behavior of the IndexedSeq iterator? As it stands, there's no real way to rely on the state of the source iterator (y in the code above) after calling e.g., take, as it may or may not need advancing afterwards (even across different Iterables in a single scala version).

Is there a better, supported, way to pull out a prefix of an iterator as a List (without looping manually) and to not invalidate the old iterator? And if take is supposed to invalidate the iterator it's called on, can that be added to the documentation?

Thanks!

@scabug
Copy link
Author

scabug commented Sep 17, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5002?orig=1
Reporter: Daniel Peebles (copumpkin)
Affected Versions: 2.9.0-1

@scabug
Copy link
Author

scabug commented Oct 10, 2011

@paulp said:
The documentation has been updated to reflect that the Iterator is undefined.

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

2 participants