@@ -131,6 +131,9 @@ object IArray:
131
131
132
132
/** Finds index of first occurrence of some value in this array after or at some start index. */
133
133
extension [T ](arr : IArray [T ]) def indexOf (elem : T , from : Int = 0 ): Int =
134
+ // `asInstanceOf` needed because `elem` does not have type `arr.T`
135
+ // We could use `arr.iterator.indexOf(elem, from)` or `arr.indexWhere(_ == elem, from)`
136
+ // but these would incur some overhead.
134
137
genericArrayOps(arr).indexOf(elem.asInstanceOf , from)
135
138
136
139
/** Finds index of the first element satisfying some predicate after or at some start index. */
@@ -163,6 +166,7 @@ object IArray:
163
166
164
167
/** Finds index of last occurrence of some value in this array before or at a given end index. */
165
168
extension [T ](arr : IArray [T ]) def lastIndexOf (elem : T , end : Int = arr.length - 1 ): Int =
169
+ // see: same issue in `indexOf`
166
170
genericArrayOps(arr).lastIndexOf(elem.asInstanceOf , end)
167
171
168
172
/** Finds index of last element satisfying some predicate before or at given end index. */
@@ -299,6 +303,8 @@ object IArray:
299
303
def tapEach [U ](f : (T ) => U ): IArray [T ] =
300
304
arr.toSeq.foreach(f)
301
305
arr
306
+ def transpose [U ](implicit asArray : T => IArray [U ]): IArray [IArray [U ]] =
307
+ genericArrayOps(arr).transpose(using asArray.asInstanceOf [T => Array [U ]])
302
308
def unzip [T1 , T2 ](using asPair : T => (T1 , T2 ), ct1 : ClassTag [T1 ], ct2 : ClassTag [T2 ]): (IArray [T1 ], IArray [T2 ]) = genericArrayOps(arr).unzip
303
309
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
304
310
def updated [U >: T : ClassTag ](index : Int , elem : U ): IArray [U ] = genericArrayOps(arr).updated(index, elem)
@@ -309,11 +315,6 @@ object IArray:
309
315
def zipAll [T1 >: T , U ](that : IArray [U ], thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
310
316
def zipAll [T1 >: T , U ](that : Iterable [U ], thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
311
317
def zipWithIndex : IArray [(T , Int )] = genericArrayOps(arr).zipWithIndex
312
- end extension
313
-
314
- extension [T ](arr : IArray [T ])
315
- def transpose [U ](implicit asArray : T => IArray [U ]): IArray [IArray [U ]] =
316
- genericArrayOps(arr).transpose(using asArray.asInstanceOf [T => Array [U ]])
317
318
318
319
extension [T , U >: T : ClassTag ](prefix : IterableOnce [T ])
319
320
def ++: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prependedAll(prefix)
@@ -442,6 +443,9 @@ object IArray:
442
443
* @return the array created from concatenating `xss`
443
444
*/
444
445
def concat [T : ClassTag ](xss : IArray [T ]* ): IArray [T ] =
446
+ // `Array.concat` should arguably take in a `Seq[Array[_ <: T]]`,
447
+ // but since it currently takes a `Seq[Array[T]]` we have to perform a cast,
448
+ // knowing tacitly that `concat` is not going to do the wrong thing.
445
449
Array .concat[T ](xss.asInstanceOf [immutable.Seq [Array [T ]]]: _* )
446
450
447
451
/** Returns an immutable array that contains the results of some element computation a number
0 commit comments