You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
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!
The text was updated successfully, but these errors were encountered: