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
It seems that application of "permutations" method to Stream instances could produce incorrect value of Iterator of Stream.
This problem is reproducable in REPL, too.
The text was updated successfully, but these errors were encountered:
@axel22 said:
Another stream-related source of fun - the permutations iterator constructs the collection by adding the current elements of the buffer into a builder. If the builder is lazy, it will add the elements from the buffer into the collection only after the elements in the buffer get swapped around.
I wrote following program to check behavior of Stream#permutations() and it compiled with scalac.
{code:title=StreamPermutationBug.scala|borderStyle=solid}
object StreamPermutationBug {
def main(args: Array[String]) {
val list = List(1, 2)
println("from: " + list)
}
}
{code}
However, the output of this program is unexpected:
{panel:title=Expected Result| borderStyle=dashed| borderColor=#ccc| titleBGColor=#F7D6C1| bgColor=#FFFFCE}
from: List(1, 2)
List(1, 2)
List(2, 1)
from: Stream(1, ?)
List(1, 2)
List(2, 1)
from: Range(1, 2)
List(1, 2)
List(2, 1)
{panel}
{panel:title=Actual Result(unexpected)| borderStyle=dashed| borderColor=#ccc| titleBGColor=#F7D6C1| bgColor=#FFFFCE}
from: List(1, 2)
List(1, 2) // expected
List(2, 1)
from: Stream(1, ?)
List(1, 1) // unexpected!
List(2, 1)
from: Range(1, 2)
List(1, 1) // unexpected!
List(2, 1)
{panel}
It seems that application of "permutations" method to Stream instances could produce incorrect value of Iterator of Stream.
This problem is reproducable in REPL, too.
The text was updated successfully, but these errors were encountered: