scala/scala — pull request #3192 by retronym (2013-11-25 09:39:16+00:00)
Title: SI-4332 Plugs the gaps in views

These currently result in runtime errors:

scala> List(1).view.distinct.force
java.lang.UnsupportedOperationException: SeqView(...).newBuilder

scala> List(1).view.inits.toList
java.lang.UnsupportedOperationException: SeqView(...).newBuilder

Two tests are enclosed:

1. reflect on the views to make any method that returns
`Repr` is overriden in `*ViewLike`. This guards against
new additions to the collections API.
2. exercise the newly added overrides

Parallel collections views are not touched, as these are likely
to be deprecated or removed shortly.

Before this change, the test reported the following.
Not all of these methods were buggy. For instance, `sortBy`,
`sortWith` are implemented in terms of `sorted` which
was implemented in `SeqViewLike`. Even in those cases, I have
opted to override the methods in the `ViewLike` to guard
against changes in the base class implementation and to
simplify the rules in the test.

========================================
Checking scala.collection.TraversableView
========================================

trait TraversableLike
----------------------------------------
def inits: Iterator[Repr]
def tails: Iterator[Repr]
override def tail: Repr
def filterNot(p: A => Boolean): Repr

========================================
Checking scala.collection.IterableView
========================================

trait TraversableLike
----------------------------------------
def inits: Iterator[Repr]
def tails: Iterator[Repr]
def filterNot(p: A => Boolean): Repr

trait IterableLike
----------------------------------------
def dropRight(n: Int): Repr
def takeRight(n: Int): Repr
def sliding(size: Int): Iterator[Repr]

========================================
Checking scala.collection.SeqView
========================================

trait SeqLike
----------------------------------------
def sortBy[B](f: A => B)(implicit ord: scala.math.Ordering[B]): Repr
def sortWith(lt: (A, A) => Boolean): Repr
def distinct: Repr
def combinations(n: Int): Iterator[Repr]
def permutations: Iterator[Repr]

trait TraversableLike
----------------------------------------
def inits: Iterator[Repr]
def tails: Iterator[Repr]
def filterNot(p: A => Boolean): Repr
def repr: Repr

trait IterableLike
----------------------------------------
def dropRight(n: Int): Repr
def takeRight(n: Int): Repr
def sliding(size: Int): Iterator[Repr]

========================================
Checking scala.collection.immutable.StreamView
========================================

trait SeqLike
----------------------------------------
def sortBy[B](f: A => B)(implicit ord: scala.math.Ordering[B]): Repr
def sortWith(lt: (A, A) => Boolean): Repr
def distinct: Repr
def combinations(n: Int): Iterator[Repr]
def permutations: Iterator[Repr]

trait TraversableLike
----------------------------------------
def inits: Iterator[Repr]
def tails: Iterator[Repr]
override def tail: Repr

trait IterableLike
----------------------------------------
def dropRight(n: Int): Repr
def takeRight(n: Int): Repr
def sliding(size: Int): Iterator[Repr]