Skip to content

Commit 96e45a7

Browse files
authored
Merge pull request #8826 from rjolly/master
Obtain an immutable array from a mutable one
2 parents dd42e2a + fe0ce76 commit 96e45a7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

library/src/scala/IArray.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ object IArray {
268268
// A convenience to avoid having to cast everything by hand
269269
private given [A] as Conversion[Array[A], IArray[A]] = identity[Sub[A]]
270270

271+
/** Convert an array into an immutable array without copying, the original array
272+
* must _not_ be mutated after this or the guaranteed immutablity of IArray will
273+
* be violated.
274+
*/
275+
def unsafeFromArray[T](s: Array[T]): IArray[T] = s
276+
271277
/** An immutable array of length 0. */
272278
def empty[T: ClassTag]: IArray[T] = new Array[T](0)
273279

0 commit comments

Comments
 (0)