NoBuilder exists so that customers can view Scala views as if they were regular collections when they were transformed. This is a dummy implementation that allows TraversableView to extend Traversable and call methods like map , without knowing if the collection is a view or a regular collection.
Longer explanation
When you call map , flatMap or scanLeft (called transformer operations) in the Scala collection, the implicit CanBuildFrom argument CanBuildFrom automatically resolved. The CanBuildFrom object is an abstract factory object for the Builder .
Most Scala collections use Builders to add items using += and create a new collection by calling result on the buidler. For instance. The given constructor b , map does the following:
def map[S, That](f: T => S)(implicit cbf: CanBuildFrom[Repr, S, That]) = { val b: Builder[S, That] = cbf(this) for (x <- this) b += f(x) b.result }
Transformation operations in views do not create a new collection. Instead, they create a lazy performance. For example, map does something like this:
def map[S, That](f: T => S)(implicit cbf: CanBuildFrom[Repr, S, That]) = new TraversableView { def foreach[U](forFunc: T => U): Unit = for (x <- self) forFunc(f(x)) }
Note that a map in the view has the same signature, but does not actually invoke += and result in the builder. Thus, the NoBuilder used in views does not really need to store items or return a collection, it is just a dummy whose methods are never called.
The same signature allows you to write this in the client code:
def foo(xs: Traversable[Int]) = xs.map(_ + 1) foo(0 until 100) foo((0 until 100).view)