1
1
package scala
2
2
import reflect .ClassTag
3
3
4
+ opaque type IArray [+ T ] = Array [_ <: T ]
5
+
4
6
/** An immutable array. An `IArray[T]` has the same representation as an `Array[T]`,
5
7
* but it cannot be updated. Unlike regular arrays, immutable arrays are covariant.
6
8
*/
7
- object opaques :
8
- opaque type IArray [+ T ] = Array [_ <: T ]
9
-
10
- private [scala] type Sub [A ] >: Array [A ] <: IArray [A ]
11
- private [scala] type Sup [A ] >: IArray [A ] <: Array [_ <: A ]
9
+ object IArray :
12
10
13
11
/** The selection operation on an immutable array.
14
12
*
@@ -314,17 +312,6 @@ object opaques:
314
312
given genericWrapUnitIArray (using DummyImplicit ): Conversion [IArray [Unit ], scala.collection.immutable.ArraySeq [Unit ]] =
315
313
arr => scala.collection.immutable.ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]])
316
314
317
- end opaques
318
-
319
- type IArray [+ T ] = opaques.IArray [T ]
320
-
321
- object IArray {
322
- import opaques .Sub
323
- import opaques .Sup
324
-
325
- // A convenience to avoid having to cast everything by hand
326
- private given [A ]: Conversion [Array [A ], IArray [A ]] = identity[Sub [A ]]
327
-
328
315
/** Convert an array into an immutable array without copying, the original array
329
316
* must _not_ be mutated after this or the guaranteed immutablity of IArray will
330
317
* be violated.
@@ -354,25 +341,25 @@ object IArray {
354
341
def emptyObjectIArray : IArray [Object ] = Array .emptyObjectArray
355
342
356
343
/** An immutable array with given elements. */
357
- inline def apply [T ](inline xs : T * )(using inline ct : ClassTag [T ]): IArray [T ] = Array (xs : _* ).asInstanceOf
344
+ def apply [T ](xs : T * )(using ct : ClassTag [T ]): IArray [T ] = Array (xs : _* ).asInstanceOf
358
345
/** An immutable array with given elements. */
359
- inline def apply (inline x : Boolean , inline xs : Boolean * ): IArray [Boolean ] = Array (x, xs : _* ).asInstanceOf
346
+ def apply (x : Boolean , xs : Boolean * ): IArray [Boolean ] = Array (x, xs : _* ).asInstanceOf
360
347
/** An immutable array with given elements. */
361
- inline def apply (inline x : Byte , inline xs : Byte * ): IArray [Byte ] = Array (x, xs : _* ).asInstanceOf
348
+ def apply (x : Byte , xs : Byte * ): IArray [Byte ] = Array (x, xs : _* ).asInstanceOf
362
349
/** An immutable array with given elements. */
363
- inline def apply (inline x : Short , inline xs : Short * ): IArray [Short ] = Array (x, xs : _* ).asInstanceOf
350
+ def apply (x : Short , xs : Short * ): IArray [Short ] = Array (x, xs : _* ).asInstanceOf
364
351
/** An immutable array with given elements. */
365
- inline def apply (inline x : Char , inline xs : Char * ): IArray [Char ] = Array (x, xs : _* ).asInstanceOf
352
+ def apply (x : Char , xs : Char * ): IArray [Char ] = Array (x, xs : _* ).asInstanceOf
366
353
/** An immutable array with given elements. */
367
- inline def apply (inline x : Int , inline xs : Int * ): IArray [Int ] = Array (x, xs : _* ).asInstanceOf
354
+ def apply (x : Int , xs : Int * ): IArray [Int ] = Array (x, xs : _* ).asInstanceOf
368
355
/** An immutable array with given elements. */
369
- inline def apply (inline x : Long , inline xs : Long * ): IArray [Long ] = Array (x, xs : _* ).asInstanceOf
356
+ def apply (x : Long , xs : Long * ): IArray [Long ] = Array (x, xs : _* ).asInstanceOf
370
357
/** An immutable array with given elements. */
371
- inline def apply (inline x : Float , inline xs : Float * ): IArray [Float ] = Array (x, xs : _* ).asInstanceOf
358
+ def apply (x : Float , xs : Float * ): IArray [Float ] = Array (x, xs : _* ).asInstanceOf
372
359
/** An immutable array with given elements. */
373
- inline def apply (inline x : Double , inline xs : Double * ): IArray [Double ] = Array (x, xs : _* ).asInstanceOf
360
+ def apply (x : Double , xs : Double * ): IArray [Double ] = Array (x, xs : _* ).asInstanceOf
374
361
/** An immutable array with given elements. */
375
- inline def apply (inline x : Unit , inline xs : Unit * ): IArray [Unit ] = Array (x, xs : _* ).asInstanceOf
362
+ def apply (x : Unit , xs : Unit * ): IArray [Unit ] = Array (x, xs : _* ).asInstanceOf
376
363
377
364
/** Concatenates all arrays into a single immutable array.
378
365
*
@@ -529,8 +516,7 @@ object IArray {
529
516
* @param x the selector value
530
517
* @return sequence wrapped in a [[scala.Some ]], if `x` is a Seq, otherwise `None`
531
518
*/
532
- def unapplySeq [T ](x : IArray [T ]) =
533
- // The double type ascription is currently needed,
534
- // for some reason (see: https://scastie.scala-lang.org/sSsmOhKxSKym405MgNRKqQ)
535
- Array .unapplySeq((x : Sup [T ]): Array [_ <: T ])
536
- }
519
+ def unapplySeq [T ](x : IArray [T ]): Array .UnapplySeqWrapper [_ <: T ] =
520
+ Array .unapplySeq(x)
521
+
522
+ end IArray
0 commit comments