Skip to content

Commit 48afa75

Browse files
committed
Get rid of view. Replace it by type alias, One class less in hierarchy.
1 parent 120e781 commit 48afa75

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/strawman/collections/CollectionStrawMan2.scala

+5-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ object CollectionStrawMan1 {
4040
def length: Int
4141
}
4242

43+
type View[A] = () => Iterator[A]
44+
4345
/* ------------ Operations ----------------------------------- */
4446

4547
/** Operations returning types unrelated to current collection */
@@ -51,7 +53,7 @@ object CollectionStrawMan1 {
5153
def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p)
5254
def isEmpty: Boolean = !iterator.hasNext
5355
def head: A = iterator.next
54-
def view: View[A] = new View(iterator)
56+
def view: View[A] = iterator _
5557
def collectAs[C[X] <: Iterable[X]](fi: FromIterator[C]): C[A] = fi.fromIterator(iterator)
5658
}
5759

@@ -210,9 +212,6 @@ object CollectionStrawMan1 {
210212
}
211213

212214
/** Concrete collection type: View */
213-
class View[+A](it: => Iterator[A]) extends CanIterate[A] {
214-
def iterator = it
215-
}
216215

217216
implicit class ViewOps[A](val v: View[A]) extends AnyVal with Ops[A] {
218217
def iterator = v.iterator
@@ -222,13 +221,13 @@ object CollectionStrawMan1 {
222221
implicit class ViewMonoTransforms[A](val v: View[A])
223222
extends AnyVal with MonoTransforms[A, View[A]] {
224223
protected def iter = v.iterator
225-
protected def fromIter(it: => Iterator[A]): View[A] = new View(it)
224+
protected def fromIter(it: => Iterator[A]): View[A] = it
226225
}
227226

228227
implicit class ViewPolyTransforms[A](val v: View[A])
229228
extends AnyVal with PolyTransforms[A, View] {
230229
protected def iter = v.iterator
231-
protected def fromIter[B](it: => Iterator[B]) = new View(it)
230+
protected def fromIter[B](it: => Iterator[B]) = it
232231
}
233232

234233
/** Concrete collection type: String */

0 commit comments

Comments
 (0)