1
1
package scala
2
2
import reflect .ClassTag
3
3
4
+ import language .experimental .captureChecking
5
+
4
6
import scala .collection .{LazyZip2 , SeqView , Searching , Stepper , StepperShape }
5
7
import scala .collection .immutable .ArraySeq
6
8
import scala .collection .mutable .{ArrayBuilder , Builder }
@@ -92,12 +94,12 @@ object IArray:
92
94
93
95
/** Builds a new array by applying a function to all elements of this array
94
96
* and using the elements of the resulting collections. */
95
- extension [T ](arr : IArray [T ]) def flatMap [U : ClassTag ](f : T => IterableOnce [U ]): IArray [U ] =
97
+ extension [T ](arr : IArray [T ]) def flatMap [U : ClassTag ](f : T => IterableOnce [U ]^ ): IArray [U ] =
96
98
genericArrayOps(arr).flatMap(f)
97
99
98
100
/** Flattens a two-dimensional array by concatenating all its rows
99
101
* into a single array. */
100
- extension [T ](arr : IArray [T ]) def flatten [U ](using asIterable : T => Iterable [U ], ct : ClassTag [U ]): IArray [U ] =
102
+ extension [T ](arr : IArray [T ]) def flatten [U ](using asIterable : T => Iterable [U ]^ , ct : ClassTag [U ]): IArray [U ] =
101
103
genericArrayOps(arr).flatten
102
104
103
105
/** Folds the elements of this array using the specified associative binary operator. */
@@ -222,7 +224,7 @@ object IArray:
222
224
genericArrayOps(arr).sortWith(f)
223
225
224
226
/** Sorts this array according to an Ordering. */
225
- extension [T ](arr : IArray [T ]) def sorted (using math.Ordering [T ]): IArray [T ] =
227
+ extension [T ](arr : IArray [T ]) def sorted (using math.Ordering [T ]^ ): IArray [T ] =
226
228
genericArrayOps(arr).sorted
227
229
228
230
/** Splits this array into a prefix/suffix pair according to a predicate. */
@@ -260,42 +262,42 @@ object IArray:
260
262
def ++ [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr) ++ suffix
261
263
def :+ [U >: T : ClassTag ](x : U ): IArray [U ] = genericArrayOps(arr) :+ x
262
264
def :++ [U >: T : ClassTag ](suffix : IArray [U ]): IArray [U ] = genericArrayOps(arr) :++ suffix
263
- def :++ [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr) :++ suffix
265
+ def :++ [U >: T : ClassTag ](suffix : IterableOnce [U ]^ ): IArray [U ] = genericArrayOps(arr) :++ suffix
264
266
def appended [U >: T : ClassTag ](x : U ): IArray [U ] = genericArrayOps(arr).appended(x)
265
267
def appendedAll [U >: T : ClassTag ](suffix : IArray [U ]): IArray [U ] = genericArrayOps(arr).appendedAll(suffix)
266
- def appendedAll [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr).appendedAll(suffix)
267
- def collect [U : ClassTag ](pf : PartialFunction [T , U ]): IArray [U ] = genericArrayOps(arr).collect(pf)
268
- def collectFirst [U ](f : PartialFunction [T , U ]): Option [U ] = genericArrayOps(arr).collectFirst(f)
268
+ def appendedAll [U >: T : ClassTag ](suffix : IterableOnce [U ]^ ): IArray [U ] = genericArrayOps(arr).appendedAll(suffix)
269
+ def collect [U : ClassTag ](pf : PartialFunction [T , U ]^ ): IArray [U ] = genericArrayOps(arr).collect(pf)
270
+ def collectFirst [U ](f : PartialFunction [T , U ]^ ): Option [U ] = genericArrayOps(arr).collectFirst(f)
269
271
def combinations (n : Int ): Iterator [IArray [T ]] = genericArrayOps(arr).combinations(n)
270
272
def concat [U >: T : ClassTag ](suffix : IArray [U ]): IArray [U ] = genericArrayOps(arr).concat(suffix)
271
- def concat [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr).concat(suffix)
273
+ def concat [U >: T : ClassTag ](suffix : IterableOnce [U ]^ ): IArray [U ] = genericArrayOps(arr).concat(suffix)
272
274
def diff [U >: T ](that : IArray [U ]): IArray [T ] = genericArrayOps(arr).diff(that.toSeq)
273
- def diff [U >: T ](that : Seq [U ]): IArray [T ] = genericArrayOps(arr).diff(that)
275
+ def diff [U >: T ](that : Seq [U ]^ ): IArray [T ] = genericArrayOps(arr).diff(that)
274
276
def distinct : IArray [T ] = genericArrayOps(arr).distinct
275
277
def distinctBy [U ](f : T => U ): IArray [T ] = genericArrayOps(arr).distinctBy(f)
276
278
def startsWith [U >: T ](that : IArray [U ]): Boolean = genericArrayOps(arr).startsWith(that, 0 )
277
279
def startsWith [U >: T ](that : IArray [U ], offset : Int ): Boolean = genericArrayOps(arr).startsWith(that, offset)
278
- def startsWith [U >: T ](that : IterableOnce [U ]): Boolean = genericArrayOps(arr).startsWith(that, 0 )
279
- def startsWith [U >: T ](that : IterableOnce [U ], offset : Int ): Boolean = genericArrayOps(arr).startsWith(that, offset)
280
+ def startsWith [U >: T ](that : IterableOnce [U ]^ ): Boolean = genericArrayOps(arr).startsWith(that, 0 )
281
+ def startsWith [U >: T ](that : IterableOnce [U ]^ , offset : Int ): Boolean = genericArrayOps(arr).startsWith(that, offset)
280
282
def endsWith [U >: T ](that : IArray [U ]): Boolean = genericArrayOps(arr).endsWith(that)
281
- def endsWith [U >: T ](that : Iterable [U ]): Boolean = genericArrayOps(arr).endsWith(that)
283
+ def endsWith [U >: T ](that : Iterable [U ]^ ): Boolean = genericArrayOps(arr).endsWith(that)
282
284
def groupBy [K ](f : T => K ): Map [K , IArray [T ]] = genericArrayOps(arr).groupBy(f)
283
285
def groupMap [K , U : ClassTag ](key : T => K )(f : T => U ): Map [K , IArray [U ]] = genericArrayOps(arr).groupMap(key)(f)
284
286
def grouped (size : Int ): Iterator [IArray [T ]] = genericArrayOps(arr).grouped(size)
285
287
def inits : Iterator [IArray [T ]] = genericArrayOps(arr).inits
286
288
def intersect [U >: T ](that : IArray [U ]): IArray [T ] = genericArrayOps(arr).intersect(that)
287
- def intersect [U >: T ](that : Seq [U ]): IArray [T ] = genericArrayOps(arr).intersect(that)
289
+ def intersect [U >: T ](that : Seq [U ]^ ): IArray [T ] = genericArrayOps(arr).intersect(that)
288
290
def lazyZip [U ](that : IArray [U ]): LazyZip2 [T , U , IArray [T ]] = genericArrayOps(arr).lazyZip[U ](that).asInstanceOf [LazyZip2 [T , U , IArray [T ]]]
289
- def lazyZip [U ](that : Iterable [U ]): LazyZip2 [T , U , IArray [T ]] = genericArrayOps(arr).lazyZip[U ](that).asInstanceOf [LazyZip2 [T , U , IArray [T ]]]
291
+ def lazyZip [U ](that : Iterable [U ]^ ): LazyZip2 [T , U , IArray [T ]] = genericArrayOps(arr).lazyZip[U ](that).asInstanceOf [LazyZip2 [T , U , IArray [T ]]]
290
292
def lengthCompare (len : Int ): Int = genericArrayOps(arr).lengthCompare(len)
291
293
def padTo [U >: T : ClassTag ](len : Int , elem : U ): IArray [U ] = genericArrayOps(arr).padTo(len, elem)
292
294
def partitionMap [T1 : ClassTag , T2 : ClassTag ](f : T => Either [T1 , T2 ]): (IArray [T1 ], IArray [T2 ]) = genericArrayOps(arr).partitionMap(f)
293
295
def patch [U >: T : ClassTag ](from : Int , other : IterableOnce [U ], replaced : Int ): IArray [U ] = genericArrayOps(arr).patch(from, other, replaced)
294
296
def permutations : Iterator [IArray [T ]] = genericArrayOps(arr).permutations
295
297
def prepended [U >: T : ClassTag ](x : U ): IArray [U ] = genericArrayOps(arr).prepended(x)
296
- def prependedAll [U >: T : ClassTag ](prefix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr).prependedAll(prefix)
298
+ def prependedAll [U >: T : ClassTag ](prefix : IterableOnce [U ]^ ): IArray [U ] = genericArrayOps(arr).prependedAll(prefix)
297
299
def reverseIterator : Iterator [T ] = genericArrayOps(arr).reverseIterator
298
- def search [U >: T ](elem : U )(using Ordering [U ]): Searching .SearchResult = arr.toSeq.search(elem)
300
+ def search [U >: T ](elem : U )(using Ordering [U ]^ ): Searching .SearchResult = arr.toSeq.search(elem)
299
301
def search [U >: T ](elem : U , from : Int , to : Int )(using Ordering [U ]): Searching .SearchResult = arr.toSeq.search(elem, from, to)
300
302
def sizeCompare (that : IArray [Any ]): Int = arr.toSeq.sizeCompare(that)
301
303
def sizeCompare (that : Iterable [? ]): Int = arr.toSeq.sizeCompare(that)
@@ -312,14 +314,14 @@ object IArray:
312
314
def unzip3 [T1 , T2 , T3 ](using asTriple : T => (T1 , T2 , T3 ), ct1 : ClassTag [T1 ], ct2 : ClassTag [T2 ], ct3 : ClassTag [T3 ]): (IArray [T1 ], IArray [T2 ], IArray [T3 ]) = genericArrayOps(arr).unzip3
313
315
def updated [U >: T : ClassTag ](index : Int , elem : U ): IArray [U ] = genericArrayOps(arr).updated(index, elem)
314
316
def view : SeqView [T ] = genericArrayOps(arr).view
315
- def withFilter (p : T => Boolean ): WithFilter [T ] = new WithFilter (p, arr)
317
+ def withFilter (p : T => Boolean ): WithFilter [T ]^ {p} = new WithFilter (p, arr)
316
318
def zip [U ](that : IArray [U ]): IArray [(T , U )] = genericArrayOps(arr).zip(that)
317
- def zip [U ](that : IterableOnce [U ]): IArray [(T , U )] = genericArrayOps(arr).zip(that)
319
+ def zip [U ](that : IterableOnce [U ]^ ): IArray [(T , U )] = genericArrayOps(arr).zip(that)
318
320
def zipAll [T1 >: T , U ](that : IArray [U ], thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
319
- def zipAll [T1 >: T , U ](that : Iterable [U ], thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
321
+ def zipAll [T1 >: T , U ](that : Iterable [U ]^ , thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
320
322
def zipWithIndex : IArray [(T , Int )] = genericArrayOps(arr).zipWithIndex
321
323
322
- extension [T , U >: T : ClassTag ](prefix : IterableOnce [T ])
324
+ extension [T , U >: T : ClassTag ](prefix : IterableOnce [T ]^ )
323
325
def ++: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prependedAll(prefix)
324
326
325
327
extension [T , U >: T : ClassTag ](prefix : IArray [T ])
@@ -444,7 +446,7 @@ object IArray:
444
446
* @param it the iterable collection
445
447
* @return an array consisting of elements of the iterable collection
446
448
*/
447
- def from [A : ClassTag ](it : IterableOnce [A ]): IArray [A ] =
449
+ def from [A : ClassTag ](it : IterableOnce [A ]^ ): IArray [A ] =
448
450
unsafeFromArray(Array .from(it))
449
451
450
452
def newBuilder [T ](using t : ClassTag [T ]): Builder [T , IArray [T ]] =
@@ -606,8 +608,8 @@ object IArray:
606
608
* @param ys an array of AnyRef
607
609
* @return true if corresponding elements are equal
608
610
*/
609
- def equals (xs : IArray [AnyRef ], ys : IArray [AnyRef ]): Boolean =
610
- Array .equals(xs.asInstanceOf [Array [AnyRef ]], ys.asInstanceOf [Array [AnyRef ]])
611
+ def equals (xs : IArray [AnyRef ^ ], ys : IArray [AnyRef ^ ]): Boolean =
612
+ Array .equals(xs.asInstanceOf [Array [AnyRef ^ {xs * } ]], ys.asInstanceOf [Array [AnyRef ^ {ys * } ]])
611
613
612
614
/** Returns a decomposition of the array into a sequence. This supports
613
615
* a pattern match like `{ case IArray(x,y,z) => println('3 elements')}`.
@@ -660,7 +662,7 @@ object IArray:
660
662
* @return a new array resulting from applying the given collection-valued function
661
663
* `f` to each element of this array and concatenating the results.
662
664
*/
663
- def flatMap [U : ClassTag ](f : T => IterableOnce [U ]): IArray [U ] = {
665
+ def flatMap [U : ClassTag ](f : T => IterableOnce [U ]^ ): IArray [U ] = {
664
666
val b = IArray .newBuilder[U ]
665
667
var i = 0
666
668
while (i < xs.length) {
@@ -671,11 +673,11 @@ object IArray:
671
673
b.result()
672
674
}
673
675
674
- def flatMap [BS , U ](f : T => BS )(using asIterable : BS => Iterable [U ], m : ClassTag [U ]): IArray [U ] =
676
+ def flatMap [BS , U ](f : T => BS )(using asIterable : BS => Iterable [U ]^ , m : ClassTag [U ]): IArray [U ] =
675
677
flatMap[U ](x => asIterable(f(x)))
676
678
677
679
/** Creates a new non-strict filter which combines this filter with the given predicate. */
678
- def withFilter (q : T => Boolean ): WithFilter [T ] = new WithFilter [T ](a => p(a) && q(a), xs)
680
+ def withFilter (q : T => Boolean ): WithFilter [T ]^ {p, q} = new WithFilter [T ](a => p(a) && q(a), xs)
679
681
680
682
end WithFilter
681
683
0 commit comments