Skip to content

Commit 5281688

Browse files
committed
Decouple views from collections. Same should be done for parallel collections.
1 parent 48afa75 commit 5281688

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/strawman/collections/CollectionStrawMan2.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ object CollectionStrawMan1 {
5353
def indexWhere(p: A => Boolean): Int = iterator.indexWhere(p)
5454
def isEmpty: Boolean = !iterator.hasNext
5555
def head: A = iterator.next
56-
def view: View[A] = iterator _
5756
def collectAs[C[X] <: Iterable[X]](fi: FromIterator[C]): C[A] = fi.fromIterator(iterator)
5857
}
5958

59+
trait Viewable[A] extends Any {
60+
def view: View[A]
61+
}
62+
6063
/** Transforms returning same collection type */
6164
trait MonoTransforms[A, Repr] extends Any {
6265
protected def iter: Iterator[A]
@@ -89,6 +92,11 @@ object CollectionStrawMan1 {
8992
def iterator = c.iterator
9093
}
9194

95+
implicit class IterableIsViewable[A](val c: Iterable[A]) extends Viewable[A]{
96+
def iterator: Iterator[A] = c.iterator
97+
def view: View[A] = iterator _
98+
}
99+
92100
/** Implementation of MonoTransforms for all generic collections */
93101
implicit class IterableMonoTransforms[A, C[X] <: Iterable[X]](val c: Iterable[A] with FromIterator[C])
94102
extends AnyVal with MonoTransforms[A, C[A]] {

0 commit comments

Comments
 (0)