Skip to content

Commit

Permalink
Fixes SI-5201. Adds flatten to TraversableViewLike.
Browse files Browse the repository at this point in the history
Note: This commit exposes a pretty rich type on flatten in views.  HOWEVER, because we don't
capture the higher kinded type of the underlying collection, it makes returning a more minimal type
pretty dang hard.  I can imagine a very breaking and painful change of capturing the underling
collection as a higher-kinded type as well as the current view type in a *ViewLike.scala.

I hope this kind of issue, along with others, drives a rethink of our view API design.
  • Loading branch information
jsuereth committed May 9, 2012
1 parent da04d69 commit a516098
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/library/scala/collection/TraversableViewLike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ trait TraversableViewLike[+A,
// if (b.isInstanceOf[NoBuilder[_]]) newFlatMapped(f).asInstanceOf[That]
// else super.flatMap[B, That](f)(bf)
}
override def flatten[B](implicit asTraversable: A => /*<:<!!!*/ GenTraversableOnce[B]) =
newFlatMapped(asTraversable)
private[this] implicit def asThis(xs: Transformed[A]): This = xs.asInstanceOf[This]

/** Boilerplate method, to override in each subclass
Expand Down
1 change: 1 addition & 0 deletions test/files/run/t5201.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
5 changes: 5 additions & 0 deletions test/files/run/t5201.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test extends App {
val seq = Seq(Seq(1, 2), Seq(3, 4)).view.flatten

Console.println(seq.isInstanceOf[collection.SeqView[_,_]])
}

0 comments on commit a516098

Please sign in to comment.