@@ -131,6 +131,9 @@ object IArray:
131131
132132 /** Finds index of first occurrence of some value in this array after or at some start index. */
133133 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.
134137 genericArrayOps(arr).indexOf(elem.asInstanceOf , from)
135138
136139 /** Finds index of the first element satisfying some predicate after or at some start index. */
@@ -163,6 +166,7 @@ object IArray:
163166
164167 /** Finds index of last occurrence of some value in this array before or at a given end index. */
165168 extension [T ](arr : IArray [T ]) def lastIndexOf (elem : T , end : Int = arr.length - 1 ): Int =
169+ // see: same issue in `indexOf`
166170 genericArrayOps(arr).lastIndexOf(elem.asInstanceOf , end)
167171
168172 /** Finds index of last element satisfying some predicate before or at given end index. */
@@ -299,6 +303,8 @@ object IArray:
299303 def tapEach [U ](f : (T ) => U ): IArray [T ] =
300304 arr.toSeq.foreach(f)
301305 arr
306+ def transpose [U ](implicit asArray : T => IArray [U ]): IArray [IArray [U ]] =
307+ genericArrayOps(arr).transpose(using asArray.asInstanceOf [T => Array [U ]])
302308 def unzip [T1 , T2 ](using asPair : T => (T1 , T2 ), ct1 : ClassTag [T1 ], ct2 : ClassTag [T2 ]): (IArray [T1 ], IArray [T2 ]) = genericArrayOps(arr).unzip
303309 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
304310 def updated [U >: T : ClassTag ](index : Int , elem : U ): IArray [U ] = genericArrayOps(arr).updated(index, elem)
@@ -309,11 +315,6 @@ object IArray:
309315 def zipAll [T1 >: T , U ](that : IArray [U ], thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
310316 def zipAll [T1 >: T , U ](that : Iterable [U ], thisElem : T1 , thatElem : U ): IArray [(T1 , U )] = genericArrayOps(arr).zipAll(that, thisElem, thatElem)
311317 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 ]])
317318
318319 extension [T , U >: T : ClassTag ](prefix : IterableOnce [T ])
319320 def ++: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prependedAll(prefix)
@@ -442,6 +443,9 @@ object IArray:
442443 * @return the array created from concatenating `xss`
443444 */
444445 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.
445449 Array .concat[T ](xss.asInstanceOf [immutable.Seq [Array [T ]]]: _* )
446450
447451 /** Returns an immutable array that contains the results of some element computation a number
0 commit comments