Skip to content

Commit 182c282

Browse files
authored
Ensure stability of IArray.tapEach (#24727)
previously in source it called `arr.toSeq.forEach`, relying on a potential flaky implicit conversion to `scala.collection.immutable.ArraySeq` and then a no-op `.toSeq` on top of that. make the conversion explicit, so that it never uses `Predef.genericWrapArray`, which would copy when calling `.toSeq`
2 parents 2209ad5 + ea7eb13 commit 182c282

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/src/scala/IArray.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ object IArray:
306306
def stepper[S <: Stepper[?]](using StepperShape[T, S]): S = genericArrayOps(arr).stepper[S]
307307
def tails: Iterator[IArray[T]] = genericArrayOps(arr).tails
308308
def tapEach[U](f: (T) => U): IArray[T] =
309-
arr.toSeq.foreach(f)
309+
IArray.genericWrapArray(arr).foreach(f) // just to be sure it doesnt clone
310310
arr
311311
def transpose[U](implicit asArray: T => IArray[U]): IArray[IArray[U]] =
312312
genericArrayOps(arr).transpose(using asArray.asInstanceOf[T => Array[U]])

0 commit comments

Comments
 (0)