Skip to content

Commit ea7eb13

Browse files
committed
Ensure stability of IArray.tapEach
previously in source it called `arr.toSeq.forEach`, relying on a potential flaky implicit conversion to scala.collection.immutable.ArraySeq. make the conversion explicit, so that it never uses Predef.genericWrapArray, which would copy when calling .toSeq
1 parent ba45875 commit ea7eb13

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)