Skip to content

Commit fcb048a

Browse files
committed
Avoid side-effects in Iterator.toString
Don't probe hasNext in Iterator.toString.
1 parent 2b4dd5b commit fcb048a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

library/src/scala/collection/Iterator.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,6 @@ trait Iterator[+A] extends TraversableOnce[A] {
786786
}
787787
else empty.next()
788788
}
789-
790-
override def toString = "unknown-if-empty iterator"
791789
}
792790

793791
(leading, trailing)
@@ -1418,11 +1416,11 @@ trait Iterator[+A] extends TraversableOnce[A] {
14181416

14191417
/** Converts this iterator to a string.
14201418
*
1421-
* @return `"empty iterator"` or `"non-empty iterator"`, depending on
1419+
* @return `"<iterator>"`
14221420
* whether or not the iterator is empty.
14231421
* @note Reuse: $preservesIterator
14241422
*/
1425-
override def toString = (if (hasNext) "non-empty" else "empty")+" iterator"
1423+
override def toString = "<iterator>"
14261424
}
14271425

14281426
/** Explicit instantiation of the `Iterator` trait to reduce class file size in subclasses. */

0 commit comments

Comments
 (0)