@@ -2,30 +2,8 @@ package scala.collection
2
2
3
3
import scala .language .implicitConversions
4
4
5
- final class LazyZipOps [A , C1 <: Iterable [A ]] private [collection](val `this` : C1 ) extends AnyVal {
6
-
7
- /** Analogous to `zip` except that the elements in each collection are not consumed until a strict operation is
8
- * invoked on the returned `LazyZip2` decorator.
9
- *
10
- * Calls to `lazyZip` can be chained to support higher arities (up to 4) without incurring the expense of
11
- * constructing and deconstructing intermediary tuples.
12
- *
13
- * {{{
14
- * val xs = List(1, 2, 3)
15
- * val res = (xs lazyZip xs lazyZip xs lazyZip xs).map((a, b, c, d) => a + b + c + d)
16
- * // res == List(4, 8, 12)
17
- * }}}
18
- *
19
- * @param that the iterable providing the second element of each eventual pair
20
- * @tparam B the type of the second element in each eventual pair
21
- * @return a decorator `LazyZip2` that allows strict operations to be performed on the lazily evaluated pairs
22
- * or chained calls to `lazyZip`. Implicit conversion to `Iterable[(A, B)]` is also supported.
23
- */
24
- def lazyZip [B ](that : Iterable [B ]): LazyZip2 [A , B , C1 ] = new LazyZip2 (`this`, that)
25
- }
26
-
27
5
/** Decorator representing lazily zipped pairs. */
28
- final class LazyZip2 [El1 , El2 , C1 <: Iterable [ El1 ]] private [collection](coll1 : C1 , coll2 : Iterable [El2 ]) {
6
+ final class LazyZip2 [+ El1 , + El2 , C1 ] private [collection](src : C1 , coll1 : Iterable [ El1 ] , coll2 : Iterable [El2 ]) {
29
7
30
8
/** Zips `that` iterable collection with an existing `LazyZip2`. The elements in each collection are
31
9
* not consumed until a strict operation is invoked on the returned `LazyZip3` decorator.
@@ -35,10 +13,10 @@ final class LazyZip2[El1, El2, C1 <: Iterable[El1]] private[collection](coll1: C
35
13
* @return a decorator `LazyZip3` that allows strict operations to be performed on the lazily evaluated tuples or
36
14
* chained calls to `lazyZip`. Implicit conversion to `Iterable[(El1, El2, B)]` is also supported.
37
15
*/
38
- def lazyZip [B ](that : Iterable [B ]): LazyZip3 [El1 , El2 , B , C1 ] = new LazyZip3 (coll1, coll2, that)
16
+ def lazyZip [B ](that : Iterable [B ]): LazyZip3 [El1 , El2 , B , C1 ] = new LazyZip3 (src, coll1, coll2, that)
39
17
40
18
def map [B , C ](f : (El1 , El2 ) => B )(implicit bf : BuildFrom [C1 , B , C ]): C = {
41
- bf.fromSpecificIterable(coll1 )(new AbstractView [B ] {
19
+ bf.fromSpecificIterable(src )(new AbstractView [B ] {
42
20
def iterator = new AbstractIterator [B ] {
43
21
private [this ] val elems1 = coll1.iterator
44
22
private [this ] val elems2 = coll2.iterator
@@ -51,7 +29,7 @@ final class LazyZip2[El1, El2, C1 <: Iterable[El1]] private[collection](coll1: C
51
29
}
52
30
53
31
def flatMap [B , C ](f : (El1 , El2 ) => Iterable [B ])(implicit bf : BuildFrom [C1 , B , C ]): C = {
54
- bf.fromSpecificIterable(coll1 )(new AbstractView [B ] {
32
+ bf.fromSpecificIterable(src )(new AbstractView [B ] {
55
33
def iterator = new AbstractIterator [B ] {
56
34
private [this ] val elems1 = coll1.iterator
57
35
private [this ] val elems2 = coll2.iterator
@@ -70,7 +48,7 @@ final class LazyZip2[El1, El2, C1 <: Iterable[El1]] private[collection](coll1: C
70
48
}
71
49
72
50
def filter [C ](p : (El1 , El2 ) => Boolean )(implicit bf : BuildFrom [C1 , (El1 , El2 ), C ]): C = {
73
- bf.fromSpecificIterable(coll1 )(new AbstractView [(El1 , El2 )] {
51
+ bf.fromSpecificIterable(src )(new AbstractView [(El1 , El2 )] {
74
52
def iterator = new AbstractIterator [(El1 , El2 )] {
75
53
private [this ] val elems1 = coll1.iterator
76
54
private [this ] val elems2 = coll2.iterator
@@ -136,9 +114,10 @@ object LazyZip2 {
136
114
137
115
138
116
/** Decorator representing lazily zipped triples. */
139
- final class LazyZip3 [El1 , El2 , El3 , C1 <: Iterable [El1 ]] private [collection](coll1 : C1 ,
140
- coll2 : Iterable [El2 ],
141
- coll3 : Iterable [El3 ]) {
117
+ final class LazyZip3 [+ El1 , + El2 , + El3 , C1 ] private [collection](src : C1 ,
118
+ coll1 : Iterable [El1 ],
119
+ coll2 : Iterable [El2 ],
120
+ coll3 : Iterable [El3 ]) {
142
121
143
122
/** Zips `that` iterable collection with an existing `LazyZip3`. The elements in each collection are
144
123
* not consumed until a strict operation is invoked on the returned `LazyZip4` decorator.
@@ -148,10 +127,10 @@ final class LazyZip3[El1, El2, El3, C1 <: Iterable[El1]] private[collection](col
148
127
* @return a decorator `LazyZip4` that allows strict operations to be performed on the lazily evaluated tuples.
149
128
* Implicit conversion to `Iterable[(El1, El2, El3, B)]` is also supported.
150
129
*/
151
- def lazyZip [B ](that : Iterable [B ]): LazyZip4 [El1 , El2 , El3 , B , C1 ] = new LazyZip4 (coll1, coll2, coll3, that)
130
+ def lazyZip [B ](that : Iterable [B ]): LazyZip4 [El1 , El2 , El3 , B , C1 ] = new LazyZip4 (src, coll1, coll2, coll3, that)
152
131
153
132
def map [B , C ](f : (El1 , El2 , El3 ) => B )(implicit bf : BuildFrom [C1 , B , C ]): C = {
154
- bf.fromSpecificIterable(coll1 )(new AbstractView [B ] {
133
+ bf.fromSpecificIterable(src )(new AbstractView [B ] {
155
134
def iterator = new AbstractIterator [B ] {
156
135
private [this ] val elems1 = coll1.iterator
157
136
private [this ] val elems2 = coll2.iterator
@@ -165,7 +144,7 @@ final class LazyZip3[El1, El2, El3, C1 <: Iterable[El1]] private[collection](col
165
144
}
166
145
167
146
def flatMap [B , C ](f : (El1 , El2 , El3 ) => Iterable [B ])(implicit bf : BuildFrom [C1 , B , C ]): C = {
168
- bf.fromSpecificIterable(coll1 )(new AbstractView [B ] {
147
+ bf.fromSpecificIterable(src )(new AbstractView [B ] {
169
148
def iterator = new AbstractIterator [B ] {
170
149
private [this ] val elems1 = coll1.iterator
171
150
private [this ] val elems2 = coll2.iterator
@@ -185,7 +164,7 @@ final class LazyZip3[El1, El2, El3, C1 <: Iterable[El1]] private[collection](col
185
164
}
186
165
187
166
def filter [C ](p : (El1 , El2 , El3 ) => Boolean )(implicit bf : BuildFrom [C1 , (El1 , El2 , El3 ), C ]): C = {
188
- bf.fromSpecificIterable(coll1 )(new AbstractView [(El1 , El2 , El3 )] {
167
+ bf.fromSpecificIterable(src )(new AbstractView [(El1 , El2 , El3 )] {
189
168
def iterator = new AbstractIterator [(El1 , El2 , El3 )] {
190
169
private [this ] val elems1 = coll1.iterator
191
170
private [this ] val elems2 = coll2.iterator
@@ -259,13 +238,14 @@ object LazyZip3 {
259
238
260
239
261
240
/** Decorator representing lazily zipped 4-tuples. */
262
- final class LazyZip4 [El1 , El2 , El3 , El4 , C1 <: Iterable [El1 ]] private [collection](coll1 : C1 ,
263
- coll2 : Iterable [El2 ],
264
- coll3 : Iterable [El3 ],
265
- coll4 : Iterable [El4 ]) {
241
+ final class LazyZip4 [+ El1 , + El2 , + El3 , + El4 , C1 ] private [collection](src : C1 ,
242
+ coll1 : Iterable [El1 ],
243
+ coll2 : Iterable [El2 ],
244
+ coll3 : Iterable [El3 ],
245
+ coll4 : Iterable [El4 ]) {
266
246
267
247
def map [B , C ](f : (El1 , El2 , El3 , El4 ) => B )(implicit bf : BuildFrom [C1 , B , C ]): C = {
268
- bf.fromSpecificIterable(coll1 )(new AbstractView [B ] {
248
+ bf.fromSpecificIterable(src )(new AbstractView [B ] {
269
249
def iterator = new AbstractIterator [B ] {
270
250
private [this ] val elems1 = coll1.iterator
271
251
private [this ] val elems2 = coll2.iterator
@@ -280,7 +260,7 @@ final class LazyZip4[El1, El2, El3, El4, C1 <: Iterable[El1]] private[collection
280
260
}
281
261
282
262
def flatMap [B , C ](f : (El1 , El2 , El3 , El4 ) => Iterable [B ])(implicit bf : BuildFrom [C1 , B , C ]): C = {
283
- bf.fromSpecificIterable(coll1 )(new AbstractView [B ] {
263
+ bf.fromSpecificIterable(src )(new AbstractView [B ] {
284
264
def iterator = new AbstractIterator [B ] {
285
265
private [this ] val elems1 = coll1.iterator
286
266
private [this ] val elems2 = coll2.iterator
@@ -301,7 +281,7 @@ final class LazyZip4[El1, El2, El3, El4, C1 <: Iterable[El1]] private[collection
301
281
}
302
282
303
283
def filter [C ](p : (El1 , El2 , El3 , El4 ) => Boolean )(implicit bf : BuildFrom [C1 , (El1 , El2 , El3 , El4 ), C ]): C = {
304
- bf.fromSpecificIterable(coll1 )(new AbstractView [(El1 , El2 , El3 , El4 )] {
284
+ bf.fromSpecificIterable(src )(new AbstractView [(El1 , El2 , El3 , El4 )] {
305
285
def iterator = new AbstractIterator [(El1 , El2 , El3 , El4 )] {
306
286
private [this ] val elems1 = coll1.iterator
307
287
private [this ] val elems2 = coll2.iterator
0 commit comments