@@ -40,6 +40,8 @@ object CollectionStrawMan1 {
40
40
def length : Int
41
41
}
42
42
43
+ type View [A ] = () => Iterator [A ]
44
+
43
45
/* ------------ Operations ----------------------------------- */
44
46
45
47
/** Operations returning types unrelated to current collection */
@@ -51,7 +53,7 @@ object CollectionStrawMan1 {
51
53
def indexWhere (p : A => Boolean ): Int = iterator.indexWhere(p)
52
54
def isEmpty : Boolean = ! iterator.hasNext
53
55
def head : A = iterator.next
54
- def view : View [A ] = new View ( iterator)
56
+ def view : View [A ] = iterator _
55
57
def collectAs [C [X ] <: Iterable [X ]](fi : FromIterator [C ]): C [A ] = fi.fromIterator(iterator)
56
58
}
57
59
@@ -210,9 +212,6 @@ object CollectionStrawMan1 {
210
212
}
211
213
212
214
/** Concrete collection type: View */
213
- class View [+ A ](it : => Iterator [A ]) extends CanIterate [A ] {
214
- def iterator = it
215
- }
216
215
217
216
implicit class ViewOps [A ](val v : View [A ]) extends AnyVal with Ops [A ] {
218
217
def iterator = v.iterator
@@ -222,13 +221,13 @@ object CollectionStrawMan1 {
222
221
implicit class ViewMonoTransforms [A ](val v : View [A ])
223
222
extends AnyVal with MonoTransforms [A , View [A ]] {
224
223
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
226
225
}
227
226
228
227
implicit class ViewPolyTransforms [A ](val v : View [A ])
229
228
extends AnyVal with PolyTransforms [A , View ] {
230
229
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
232
231
}
233
232
234
233
/** Concrete collection type: String */
0 commit comments