Skip to content

Commit 5af7f23

Browse files
committed
Merge pull request scala#4718 from Ichoran/issue/9379
SI-9379 Added toString to .zipped to allow Stream etc to short-circuit
2 parents fcbb0e2 + 2c16790 commit 5af7f23

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/library/scala/runtime/Tuple2Zipped.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ final class Tuple2Zipped[El1, Repr1, El2, Repr2](val colls: (TraversableLike[El1
110110
return
111111
}
112112
}
113+
114+
override def toString = "(%s, %s).zipped".format(colls._1.toString, colls._2.toString)
113115
}
114116

115117
object Tuple2Zipped {

src/library/scala/runtime/Tuple3Zipped.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ final class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3](val colls: (Travers
118118
return
119119
}
120120
}
121+
122+
override def toString: String = "(%s, %s, %s).zipped".format(colls._1.toString, colls._2.toString, colls._3.toString)
121123
}
122124

123125
object Tuple3Zipped {

test/junit/scala/collection/immutable/StreamTest.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,20 @@ class StreamTest {
107107
def withFilter_map_properly_lazy_in_tail: Unit = {
108108
assertStreamOpLazyInTail(_.withFilter(_ % 2 == 0).map(identity), List(1, 2))
109109
}
110+
111+
@Test
112+
def test_si9379() {
113+
class Boom {
114+
private var i = -1
115+
def inc = {
116+
i += 1
117+
if (i > 1000) throw new NoSuchElementException("Boom! Too many elements!")
118+
i
119+
}
120+
}
121+
val b = new Boom
122+
val s = Stream.continually(b.inc)
123+
// zipped.toString must allow s to short-circuit evaluation
124+
assertTrue((s, s).zipped.toString contains s.toString)
125+
}
110126
}

0 commit comments

Comments
 (0)