Permalink
Browse files

Fixes si-5656.

  • Loading branch information...
axel22 committed May 4, 2012
1 parent f146d58 commit bbd6a3d6da09a6f8caf082a25b27be74bf59c124
Showing with 25 additions and 5 deletions.
  1. +13 −5 src/library/scala/collection/TraversableViewLike.scala
  2. +1 −0 test/files/run/t5656.check
  3. +11 −0 test/files/run/t5656.scala
@@ -28,8 +28,16 @@ trait ViewMkString[+A] {
override def mkString(start: String, sep: String, end: String): String = {
thisSeq.addString(new StringBuilder(), start, sep, end).toString
}
override def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder =
b append start append "..." append end
override def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder = {
var first = true
b append start
for (x <- self) {
if (first) first = false else b append sep
b append x
}
b append end
b
}
}
/** A template trait for non-strict views of traversable collections.
@@ -41,17 +49,17 @@ trait ViewMkString[+A] {
* that takes a `View` as its `From` type parameter must yield the same view (or a generic
* superclass of it) as its result parameter. If that assumption is broken, cast errors might result.
*
* @define viewInfo
* @define viewInfo
* A view is a lazy version of some collection. Collection transformers such as
* `map` or `filter` or `++` do not traverse any elements when applied on a view.
* Instead they create a new view which simply records that fact that the operation
* needs to be applied. The collection elements are accessed, and the view operations are applied,
* when a non-view result is needed, or when the `force` method is called on a view.
* @define traversableViewInfo
* @define traversableViewInfo
* $viewInfo
*
* All views for traversable collections are defined by creating a new `foreach` method.
*
* @author Martin Odersky
* @version 2.8
* @since 2.8
@@ -0,0 +1 @@
List(1, 2, 3)_List(a, b, c)
View
@@ -0,0 +1,11 @@
object Test {
def main(args: Array[String]) {
println(Seq(List('1', '2', '3'), List('a', 'b', 'c')).view.addString(new StringBuilder, "_"))
}
}

0 comments on commit bbd6a3d

Please sign in to comment.