@@ -2,7 +2,7 @@ package scala
2
2
import reflect .ClassTag
3
3
4
4
import scala .collection ._
5
- import scala .collection .mutable .IArrayBuilder
5
+ import scala .collection .mutable .{ IArrayBuilder , Buffer }
6
6
7
7
opaque type IArray [+ T ] = Array [_ <: T ]
8
8
@@ -258,6 +258,9 @@ object IArray:
258
258
def :+ [U >: T : ClassTag ](x : U ): IArray [U ] = genericArrayOps(arr) :+ x
259
259
def :++ [U >: T : ClassTag ](suffix : IArray [U ]): IArray [U ] = genericArrayOps(arr) :++ suffix
260
260
def :++ [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr) :++ suffix
261
+ def addString (b : mutable.StringBuilder ): mutable.StringBuilder = arr.toSeq.addString(b)
262
+ def addString (b : mutable.StringBuilder , sep : String ): mutable.StringBuilder = arr.toSeq.addString(b, sep)
263
+ def addString (b : mutable.StringBuilder , start : String , sep : String , end : String ): mutable.StringBuilder = arr.toSeq.addString(b, start, sep, end)
261
264
def appended [U >: T : ClassTag ](x : U ): IArray [U ] = genericArrayOps(arr).appended(x)
262
265
def appendedAll [U >: T : ClassTag ](suffix : IArray [U ]): IArray [U ] = genericArrayOps(arr).appendedAll(suffix)
263
266
def appendedAll [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr).appendedAll(suffix)
@@ -266,45 +269,91 @@ object IArray:
266
269
def combinations (n : Int ): Iterator [IArray [T ]] = genericArrayOps(arr).combinations(n)
267
270
def concat [U >: T : ClassTag ](suffix : IArray [U ]): IArray [U ] = genericArrayOps(arr).concat(suffix)
268
271
def concat [U >: T : ClassTag ](suffix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr).concat(suffix)
272
+ def containsSlice [U ](that : IArray [U ]): Boolean = arr.toSeq.containsSlice(that.toSeq)
273
+ def containsSlice [U ](that : Seq [U ]): Boolean = arr.toSeq.containsSlice(that)
274
+ def corresponds [U ](that : IArray [U ])(p : (T , U ) => Boolean ): Boolean = arr.toSeq.corresponds(that.toSeq)(p)
275
+ def corresponds [U ](that : IterableOnce [U ])(p : (T , U ) => Boolean ): Boolean = arr.toSeq.corresponds(that)(p)
269
276
def diff [U >: T ](that : IArray [U ]): IArray [T ] = genericArrayOps(arr).diff(that.toSeq)
270
277
def diff [U >: T ](that : Seq [U ]): IArray [T ] = genericArrayOps(arr).diff(that)
271
278
def distinct : IArray [T ] = genericArrayOps(arr).distinct
272
279
def distinctBy [U ](f : T => U ): IArray [T ] = genericArrayOps(arr).distinctBy(f)
280
+ def empty : immutable.ArraySeq [T ] = arr.toSeq.empty
273
281
def startsWith [U >: T ](that : IArray [U ]): Boolean = genericArrayOps(arr).startsWith(that, 0 )
274
282
def startsWith [U >: T ](that : IArray [U ], offset : Int ): Boolean = genericArrayOps(arr).startsWith(that, offset)
275
283
def startsWith [U >: T ](that : IterableOnce [U ]): Boolean = genericArrayOps(arr).startsWith(that, 0 )
276
284
def startsWith [U >: T ](that : IterableOnce [U ], offset : Int ): Boolean = genericArrayOps(arr).startsWith(that, offset)
277
285
def endsWith [U >: T ](that : IArray [U ]): Boolean = genericArrayOps(arr).endsWith(that)
278
286
def endsWith [U >: T ](that : Iterable [U ]): Boolean = genericArrayOps(arr).endsWith(that)
287
+ def findLast (p : T => Boolean ): Option [T ] = arr.toSeq.findLast(p)
279
288
def groupBy [K ](f : T => K ): immutable.Map [K , IArray [T ]] = genericArrayOps(arr).groupBy(f)
280
289
def groupMap [K , U : ClassTag ](key : T => K )(f : T => U ): immutable.Map [K , IArray [U ]] = genericArrayOps(arr).groupMap(key)(f)
290
+ def groupMapReduce [K , U ](key : (T ) => K )(f : (T ) => U )(reduce : (U , U ) => U ): immutable.Map [K , U ] = arr.toSeq.groupMapReduce(key)(f)(reduce)
281
291
def grouped (size : Int ): Iterator [IArray [T ]] = genericArrayOps(arr).grouped(size)
292
+ def indexOfSlice [U >: T ](that : IArray [U ]): Int = arr.toSeq.indexOfSlice(that)
293
+ def indexOfSlice [U >: T ](that : Seq [U ]): Int = arr.toSeq.indexOfSlice(that)
294
+ def indexOfSlice [U >: T ](that : IArray [U ], from : Int ): Int = arr.toSeq.indexOfSlice(that, from)
295
+ def indexOfSlice [U >: T ](that : Seq [U ], from : Int ): Int = arr.toSeq.indexOfSlice(that, from)
282
296
def inits : Iterator [IArray [T ]] = genericArrayOps(arr).inits
283
297
def intersect [U >: T ](that : IArray [U ]): IArray [T ] = genericArrayOps(arr).intersect(that)
284
298
def intersect [U >: T ](that : Seq [U ]): IArray [T ] = genericArrayOps(arr).intersect(that)
299
+ def isTraversableAgain : Boolean = arr.toSeq.isTraversableAgain
300
+ def knownSize : Int = arr.length
301
+ def lastIndexOfSlice [U >: T ](that : IArray [U ]): Int = arr.toSeq.lastIndexOfSlice(that)
302
+ def lastIndexOfSlice [U >: T ](that : Seq [U ]): Int = arr.toSeq.lastIndexOfSlice(that)
303
+ def lastIndexOfSlice [U >: T ](that : IArray [U ], end : Int ): Int = arr.toSeq.lastIndexOfSlice(that, end)
304
+ def lastIndexOfSlice [U >: T ](that : Seq [U ], end : Int ): Int = arr.toSeq.lastIndexOfSlice(that, end)
285
305
def lazyZip [U ](that : IArray [U ]): LazyZip2 [T , U , IArray [T ]] = genericArrayOps(arr).lazyZip[U ](that).asInstanceOf [LazyZip2 [T , U , IArray [T ]]]
286
306
def lazyZip [U ](that : Iterable [U ]): LazyZip2 [T , U , IArray [T ]] = genericArrayOps(arr).lazyZip[U ](that).asInstanceOf [LazyZip2 [T , U , IArray [T ]]]
287
307
def lengthCompare (len : Int ): Int = genericArrayOps(arr).lengthCompare(len)
308
+ def lengthIs : IterableOps .SizeCompareOps = arr.toSeq.lengthIs
309
+ def max [U >: T ](using math.Ordering [U ]): T = arr.toSeq.max[U ]
310
+ def maxBy [U ](f : T => U )(using math.Ordering [U ]): T = arr.toSeq.maxBy(f)
311
+ def maxByOption [U ](f : T => U )(using math.Ordering [U ]): Option [T ] = arr.toSeq.maxByOption(f)
312
+ def maxOption [U >: T ](using math.Ordering [U ]): Option [U ] = arr.toSeq.maxOption[U ]
313
+ def min [U >: T ](using math.Ordering [U ]): T = arr.toSeq.min[U ]
314
+ def minBy [U ](f : T => U )(using math.Ordering [U ]): T = arr.toSeq.minBy(f)
315
+ def minByOption [U ](f : T => U )(using math.Ordering [U ]): Option [T ] = arr.toSeq.minByOption(f)
316
+ def minOption [U >: T ](using math.Ordering [U ]): Option [U ] = arr.toSeq.minOption[U ]
317
+ def mkString : String = arr.toSeq.mkString
318
+ def mkString (sep : String ): String = arr.toSeq.mkString(sep)
319
+ def mkString (start : String , sep : String , end : String ): String = arr.toSeq.mkString(start, sep, end)
288
320
def padTo [U >: T : ClassTag ](len : Int , elem : U ): IArray [U ] = genericArrayOps(arr).padTo(len, elem)
289
321
def partitionMap [T1 : ClassTag , T2 : ClassTag ](f : T => Either [T1 , T2 ]): (IArray [T1 ], IArray [T2 ]) = genericArrayOps(arr).partitionMap(f)
290
322
def patch [U >: T : ClassTag ](from : Int , other : IterableOnce [U ], replaced : Int ): IArray [U ] = genericArrayOps(arr).patch(from, other, replaced)
291
323
def permutations : Iterator [IArray [T ]] = genericArrayOps(arr).permutations
292
324
def prepended [U >: T : ClassTag ](x : U ): IArray [U ] = genericArrayOps(arr).prepended(x)
293
325
def prependedAll [U >: T : ClassTag ](prefix : IterableOnce [U ]): IArray [U ] = genericArrayOps(arr).prependedAll(prefix)
326
+ def product [U >: T ](using math.Numeric [U ]): U = arr.toSeq.product[U ]
327
+ def reduce [U >: T ](op : (U , U ) => U ): U = arr.toSeq.reduce(op)
328
+ def reduceLeft [U >: T ](op : (U , T ) => U ): U = arr.toSeq.reduceLeft(op)
329
+ def reduceRight [U >: T ](op : (T , U ) => U ): U = arr.toSeq.reduceRight(op)
294
330
def reverseIterator : Iterator [T ] = genericArrayOps(arr).reverseIterator
331
+ def sameElements [U >: T ](that : IArray [U ]): Boolean = arr.toSeq.sameElements(that)
332
+ def sameElements [U >: T ](that : IterableOnce [U ]): Boolean = arr.toSeq.sameElements(that)
295
333
def search [U >: T ](elem : U )(using Ordering [U ]): Searching .SearchResult = arr.toSeq.search(elem)
296
334
def search [U >: T ](elem : U , from : Int , to : Int )(using Ordering [U ]): Searching .SearchResult = arr.toSeq.search(elem, from, to)
335
+ def segmentLength (p : (T ) => Boolean , from : Int ): Int = arr.toSeq.segmentLength(p, from)
336
+ def segmentLength (p : (T ) => Boolean ): Int = arr.toSeq.segmentLength(p)
297
337
def sizeCompare (that : IArray [Any ]): Int = arr.toSeq.sizeCompare(that)
298
338
def sizeCompare (that : Iterable [_]): Int = arr.toSeq.sizeCompare(that)
299
339
def sizeCompare (otherSize : Int ): Int = genericArrayOps(arr).sizeCompare(otherSize)
340
+ def sizeIs : IterableOps .SizeCompareOps = arr.toSeq.sizeIs
300
341
def sliding (size : Int , step : Int = 1 ): Iterator [IArray [T ]] = genericArrayOps(arr).sliding(size, step)
301
342
def stepper [S <: Stepper [_]](using StepperShape [T , S ]): S = genericArrayOps(arr).stepper[S ]
343
+ def sum [U >: T ](using math.Numeric [U ]): U = arr.toSeq.sum[U ]
302
344
def tails : Iterator [IArray [T ]] = genericArrayOps(arr).tails
303
345
def tapEach [U ](f : (T ) => U ): IArray [T ] =
304
346
arr.toSeq.foreach(f)
305
347
arr
306
348
def transpose [U ](implicit asArray : T => IArray [U ]): IArray [IArray [U ]] =
307
349
genericArrayOps(arr).transpose(using asArray.asInstanceOf [T => Array [U ]])
350
+ def to [C1 ](factory : Factory [T , C1 ]): C1 = arr.toSeq.to(factory)
351
+ def toBuffer [U >: T ]: Buffer [U ] = arr.toSeq.toBuffer[U ]
352
+ def toIndexedSeq : immutable.IndexedSeq [T ] = arr.toSeq.toIndexedSeq
353
+ def toIterable : Iterable [T ] = arr.toSeq.toIterable
354
+ def toList : List [T ] = arr.toSeq.toList
355
+ def toSet : Set [T ] = arr.toSeq.toSet
356
+ def toVector : Vector [T ] = arr.toSeq.toVector
308
357
def unzip [T1 , T2 ](using asPair : T => (T1 , T2 ), ct1 : ClassTag [T1 ], ct2 : ClassTag [T2 ]): (IArray [T1 ], IArray [T2 ]) = genericArrayOps(arr).unzip
309
358
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
310
359
def updated [U >: T : ClassTag ](index : Int , elem : U ): IArray [U ] = genericArrayOps(arr).updated(index, elem)
@@ -325,49 +374,85 @@ object IArray:
325
374
extension [T , U >: T : ClassTag ](x : T )
326
375
def +: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prepended(x)
327
376
377
+ extension [T1 , T2 ](arr : IArray [(T1 , T2 )])
378
+ def toMap : Map [T1 , T2 ] = arr.toSeq.toMap
379
+
380
+ /** Conversion from IArray to immutable.ArraySeq */
381
+ extension [T ](arr : IArray [T ]) def toSeq : immutable.ArraySeq [T ] =
382
+ immutable.ArraySeq .unsafeWrapArray(arr.asInstanceOf [Array [T ]])
383
+
384
+ /** Conversion from IArray to immutable.ArraySeq */
385
+ extension [T <: AnyRef ](arr : IArray [T ]) def toSeq : immutable.ArraySeq [T ] =
386
+ immutable.ArraySeq .ofRef(arr.asInstanceOf [Array [T ]])
387
+
388
+ /** Conversion from IArray to immutable.ArraySeq */
389
+ extension (arr : IArray [Int ]) def toSeq : immutable.ArraySeq [Int ] =
390
+ immutable.ArraySeq .ofInt(arr.asInstanceOf [Array [Int ]])
391
+
392
+ /** Conversion from IArray to immutable.ArraySeq */
393
+ extension (arr : IArray [Double ]) def toSeq : immutable.ArraySeq [Double ] =
394
+ immutable.ArraySeq .ofDouble(arr.asInstanceOf [Array [Double ]])
395
+
396
+ /** Conversion from IArray to immutable.ArraySeq */
397
+ extension (arr : IArray [Long ]) def toSeq : immutable.ArraySeq [Long ] =
398
+ immutable.ArraySeq .ofLong(arr.asInstanceOf [Array [Long ]])
399
+
400
+ /** Conversion from IArray to immutable.ArraySeq */
401
+ extension (arr : IArray [Float ]) def toSeq : immutable.ArraySeq [Float ] =
402
+ immutable.ArraySeq .ofFloat(arr.asInstanceOf [Array [Float ]])
403
+
404
+ /** Conversion from IArray to immutable.ArraySeq */
405
+ extension (arr : IArray [Char ]) def toSeq : immutable.ArraySeq [Char ] =
406
+ immutable.ArraySeq .ofChar(arr.asInstanceOf [Array [Char ]])
407
+
408
+ /** Conversion from IArray to immutable.ArraySeq */
409
+ extension (arr : IArray [Byte ]) def toSeq : immutable.ArraySeq [Byte ] =
410
+ immutable.ArraySeq .ofByte(arr.asInstanceOf [Array [Byte ]])
411
+
412
+ /** Conversion from IArray to immutable.ArraySeq */
413
+ extension (arr : IArray [Short ]) def toSeq : immutable.ArraySeq [Short ] =
414
+ immutable.ArraySeq .ofShort(arr.asInstanceOf [Array [Short ]])
415
+
416
+ /** Conversion from IArray to immutable.ArraySeq */
417
+ extension (arr : IArray [Boolean ]) def toSeq : immutable.ArraySeq [Boolean ] =
418
+ immutable.ArraySeq .ofBoolean(arr.asInstanceOf [Array [Boolean ]])
419
+
420
+ /** Conversion from IArray to immutable.ArraySeq */
421
+ extension (arr : IArray [Unit ]) def toSeq : immutable.ArraySeq [Unit ] =
422
+ immutable.ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]])
423
+
328
424
/** Conversion from IArray to immutable.ArraySeq */
329
- given genericWrapIArray [T ](using DummyImplicit ): Conversion [IArray [T ], scala.collection.immutable.ArraySeq [T ]] =
330
- arr => scala.collection.immutable.ArraySeq .unsafeWrapArray(arr.asInstanceOf [Array [T ]])
425
+ given genericWrapIArray [T ](using DummyImplicit ): Conversion [IArray [T ], immutable.ArraySeq [T ]] = _.toSeq
331
426
332
427
/** Conversion from IArray to immutable.ArraySeq */
333
- given genericWrapAnyRefIArray [T <: AnyRef ](using DummyImplicit ): Conversion [IArray [T ], scala.collection.immutable.ArraySeq [T ]] =
334
- arr => scala.collection.immutable.ArraySeq .ofRef(arr.asInstanceOf [Array [T ]])
428
+ given genericWrapAnyRefIArray [T <: AnyRef ](using DummyImplicit ): Conversion [IArray [T ], immutable.ArraySeq [T ]] = _.toSeq
335
429
336
430
/** Conversion from IArray to immutable.ArraySeq */
337
- given genericWrapIntIArray (using DummyImplicit ): Conversion [IArray [Int ], scala.collection.immutable.ArraySeq [Int ]] =
338
- arr => scala.collection.immutable.ArraySeq .ofInt(arr.asInstanceOf [Array [Int ]])
431
+ given genericWrapIntIArray (using DummyImplicit ): Conversion [IArray [Int ], immutable.ArraySeq [Int ]] = _.toSeq
339
432
340
433
/** Conversion from IArray to immutable.ArraySeq */
341
- given genericWrapDoubleIArray (using DummyImplicit ): Conversion [IArray [Double ], scala.collection.immutable.ArraySeq [Double ]] =
342
- arr => scala.collection.immutable.ArraySeq .ofDouble(arr.asInstanceOf [Array [Double ]])
434
+ given genericWrapDoubleIArray (using DummyImplicit ): Conversion [IArray [Double ], immutable.ArraySeq [Double ]] = _.toSeq
343
435
344
436
/** Conversion from IArray to immutable.ArraySeq */
345
- given genericWrapLongIArray (using DummyImplicit ): Conversion [IArray [Long ], scala.collection.immutable.ArraySeq [Long ]] =
346
- arr => scala.collection.immutable.ArraySeq .ofLong(arr.asInstanceOf [Array [Long ]])
437
+ given genericWrapLongIArray (using DummyImplicit ): Conversion [IArray [Long ], immutable.ArraySeq [Long ]] = _.toSeq
347
438
348
439
/** Conversion from IArray to immutable.ArraySeq */
349
- given genericWrapFloatIArray (using DummyImplicit ): Conversion [IArray [Float ], scala.collection.immutable.ArraySeq [Float ]] =
350
- arr => scala.collection.immutable.ArraySeq .ofFloat(arr.asInstanceOf [Array [Float ]])
440
+ given genericWrapFloatIArray (using DummyImplicit ): Conversion [IArray [Float ], immutable.ArraySeq [Float ]] = _.toSeq
351
441
352
442
/** Conversion from IArray to immutable.ArraySeq */
353
- given genericWrapCharIArray (using DummyImplicit ): Conversion [IArray [Char ], scala.collection.immutable.ArraySeq [Char ]] =
354
- arr => scala.collection.immutable.ArraySeq .ofChar(arr.asInstanceOf [Array [Char ]])
443
+ given genericWrapCharIArray (using DummyImplicit ): Conversion [IArray [Char ], immutable.ArraySeq [Char ]] = _.toSeq
355
444
356
445
/** Conversion from IArray to immutable.ArraySeq */
357
- given genericWrapByteIArray (using DummyImplicit ): Conversion [IArray [Byte ], scala.collection.immutable.ArraySeq [Byte ]] =
358
- arr => scala.collection.immutable.ArraySeq .ofByte(arr.asInstanceOf [Array [Byte ]])
446
+ given genericWrapByteIArray (using DummyImplicit ): Conversion [IArray [Byte ], immutable.ArraySeq [Byte ]] = _.toSeq
359
447
360
448
/** Conversion from IArray to immutable.ArraySeq */
361
- given genericWrapShortIArray (using DummyImplicit ): Conversion [IArray [Short ], scala.collection.immutable.ArraySeq [Short ]] =
362
- arr => scala.collection.immutable.ArraySeq .ofShort(arr.asInstanceOf [Array [Short ]])
449
+ given genericWrapShortIArray (using DummyImplicit ): Conversion [IArray [Short ], immutable.ArraySeq [Short ]] = _.toSeq
363
450
364
451
/** Conversion from IArray to immutable.ArraySeq */
365
- given genericWrapBooleanIArray (using DummyImplicit ): Conversion [IArray [Boolean ], scala.collection.immutable.ArraySeq [Boolean ]] =
366
- arr => scala.collection.immutable.ArraySeq .ofBoolean(arr.asInstanceOf [Array [Boolean ]])
452
+ given genericWrapBooleanIArray (using DummyImplicit ): Conversion [IArray [Boolean ], immutable.ArraySeq [Boolean ]] = _.toSeq
367
453
368
454
/** Conversion from IArray to immutable.ArraySeq */
369
- given genericWrapUnitIArray (using DummyImplicit ): Conversion [IArray [Unit ], scala.collection.immutable.ArraySeq [Unit ]] =
370
- arr => scala.collection.immutable.ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]])
455
+ given genericWrapUnitIArray (using DummyImplicit ): Conversion [IArray [Unit ], immutable.ArraySeq [Unit ]] = _.toSeq
371
456
372
457
/** Convert an array into an immutable array without copying, the original array
373
458
* must _not_ be mutated after this or the guaranteed immutablity of IArray will
0 commit comments