Skip to content

Commit 04ea027

Browse files
committed
Add converion from IArray to immutable.ArraySeq
1 parent 85b699e commit 04ea027

File tree

1 file changed

+22
-107
lines changed

1 file changed

+22
-107
lines changed

library/src/scala/IArray.scala

Lines changed: 22 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ object IArray:
254254
def :+ [U >: T: ClassTag](x: U): IArray[U] = genericArrayOps(arr) :+ x
255255
def :++ [U >: T: ClassTag](suffix: IArray[U]): IArray[U] = genericArrayOps(arr) :++ suffix
256256
def :++ [U >: T: ClassTag](suffix: IterableOnce[U]): IArray[U] = genericArrayOps(arr) :++ suffix
257-
def addString(b: mutable.StringBuilder): mutable.StringBuilder = arr.toSeq.addString(b)
258-
def addString(b: mutable.StringBuilder, sep: String): mutable.StringBuilder = arr.toSeq.addString(b, sep)
259-
def addString(b: mutable.StringBuilder, start: String, sep: String, end: String): mutable.StringBuilder = arr.toSeq.addString(b, start, sep, end)
260257
def appended[U >: T: ClassTag](x: U): IArray[U] = genericArrayOps(arr).appended(x)
261258
def appendedAll[U >: T: ClassTag](suffix: IArray[U]): IArray[U] = genericArrayOps(arr).appendedAll(suffix)
262259
def appendedAll[U >: T: ClassTag](suffix: IterableOnce[U]): IArray[U] = genericArrayOps(arr).appendedAll(suffix)
@@ -265,89 +262,43 @@ object IArray:
265262
def combinations(n: Int): Iterator[IArray[T]] = genericArrayOps(arr).combinations(n)
266263
def concat[U >: T: ClassTag](suffix: IArray[U]): IArray[U] = genericArrayOps(arr).concat(suffix)
267264
def concat[U >: T: ClassTag](suffix: IterableOnce[U]): IArray[U] = genericArrayOps(arr).concat(suffix)
268-
def containsSlice[U](that: IArray[U]): Boolean = arr.toSeq.containsSlice(that.toSeq)
269-
def containsSlice[U](that: Seq[U]): Boolean = arr.toSeq.containsSlice(that)
270-
def corresponds[U](that: IArray[U])(p: (T, U) => Boolean): Boolean = arr.toSeq.corresponds(that.toSeq)(p)
271-
def corresponds[U](that: IterableOnce[U])(p: (T, U) => Boolean): Boolean = arr.toSeq.corresponds(that)(p)
272265
def diff[U >: T](that: IArray[U]): IArray[T] = genericArrayOps(arr).diff(that.toSeq)
273266
def diff[U >: T](that: Seq[U]): IArray[T] = genericArrayOps(arr).diff(that)
274267
def distinct: IArray[T] = genericArrayOps(arr).distinct
275268
def distinctBy[U](f: T => U): IArray[T] = genericArrayOps(arr).distinctBy(f)
276-
def empty: immutable.ArraySeq[T] = arr.toSeq.empty
277269
def startsWith[U >: T](that: IArray[U]): Boolean = genericArrayOps(arr).startsWith(that, 0)
278270
def startsWith[U >: T](that: IArray[U], offset: Int): Boolean = genericArrayOps(arr).startsWith(that, offset)
279271
def startsWith[U >: T](that: IterableOnce[U]): Boolean = genericArrayOps(arr).startsWith(that, 0)
280272
def startsWith[U >: T](that: IterableOnce[U], offset: Int): Boolean = genericArrayOps(arr).startsWith(that, offset)
281273
def endsWith[U >: T](that: IArray[U]): Boolean = genericArrayOps(arr).endsWith(that)
282274
def endsWith[U >: T](that: Iterable[U]): Boolean = genericArrayOps(arr).endsWith(that)
283-
def findLast(p: T => Boolean): Option[T] = arr.toSeq.findLast(p)
284275
def groupBy[K](f: T => K): immutable.Map[K, IArray[T]] = genericArrayOps(arr).groupBy(f)
285276
def groupMap[K, U: ClassTag](key: T => K)(f: T => U): immutable.Map[K, IArray[U]] = genericArrayOps(arr).groupMap(key)(f)
286-
def groupMapReduce[K, U](key: (T) => K)(f: (T) => U)(reduce: (U, U) => U): immutable.Map[K, U] = arr.toSeq.groupMapReduce(key)(f)(reduce)
287277
def grouped(size: Int): Iterator[IArray[T]] = genericArrayOps(arr).grouped(size)
288-
def indexOfSlice[U >: T](that: IArray[U]): Int = arr.toSeq.indexOfSlice(that)
289-
def indexOfSlice[U >: T](that: Seq[U]): Int = arr.toSeq.indexOfSlice(that)
290-
def indexOfSlice[U >: T](that: IArray[U], from: Int): Int = arr.toSeq.indexOfSlice(that, from)
291-
def indexOfSlice[U >: T](that: Seq[U], from: Int): Int = arr.toSeq.indexOfSlice(that, from)
292278
def inits: Iterator[IArray[T]] = genericArrayOps(arr).inits
293279
def intersect[U >: T](that: IArray[U]): IArray[T] = genericArrayOps(arr).intersect(that)
294280
def intersect[U >: T](that: Seq[U]): IArray[T] = genericArrayOps(arr).intersect(that)
295-
def isTraversableAgain: Boolean = arr.toSeq.isTraversableAgain
296-
def knownSize: Int = arr.length
297-
def lastIndexOfSlice[U >: T](that: IArray[U]): Int = arr.toSeq.lastIndexOfSlice(that)
298-
def lastIndexOfSlice[U >: T](that: Seq[U]): Int = arr.toSeq.lastIndexOfSlice(that)
299-
def lastIndexOfSlice[U >: T](that: IArray[U], end: Int): Int = arr.toSeq.lastIndexOfSlice(that, end)
300-
def lastIndexOfSlice[U >: T](that: Seq[U], end: Int): Int = arr.toSeq.lastIndexOfSlice(that, end)
301281
def lazyZip[U](that: IArray[U]): LazyZip2[T, U, IArray[T]] = genericArrayOps(arr).lazyZip[U](that).asInstanceOf[LazyZip2[T, U, IArray[T]]]
302282
def lazyZip[U](that: Iterable[U]): LazyZip2[T, U, IArray[T]] = genericArrayOps(arr).lazyZip[U](that).asInstanceOf[LazyZip2[T, U, IArray[T]]]
303283
def lengthCompare(len: Int): Int = genericArrayOps(arr).lengthCompare(len)
304-
def lengthIs: IterableOps.SizeCompareOps = arr.toSeq.lengthIs
305-
def max[U >: T](using math.Ordering[U]): T = arr.toSeq.max[U]
306-
def maxBy[U](f: T => U)(using math.Ordering[U]): T = arr.toSeq.maxBy(f)
307-
def maxByOption[U](f: T => U)(using math.Ordering[U]): Option[T] = arr.toSeq.maxByOption(f)
308-
def maxOption[U >: T](using math.Ordering[U]): Option[U] = arr.toSeq.maxOption[U]
309-
def min[U >: T](using math.Ordering[U]): T = arr.toSeq.min[U]
310-
def minBy[U](f: T => U)(using math.Ordering[U]): T = arr.toSeq.minBy(f)
311-
def minByOption[U](f: T => U)(using math.Ordering[U]): Option[T] = arr.toSeq.minByOption(f)
312-
def minOption[U >: T](using math.Ordering[U]): Option[U] = arr.toSeq.minOption[U]
313-
def mkString: String = arr.toSeq.mkString
314-
def mkString(sep: String): String = arr.toSeq.mkString(sep)
315-
def mkString(start: String, sep: String, end: String): String = arr.toSeq.mkString(start, sep, end)
316284
def padTo[U >: T: ClassTag](len: Int, elem: U): IArray[U] = genericArrayOps(arr).padTo(len, elem)
317285
def partitionMap[T1: ClassTag, T2: ClassTag](f: T => Either[T1, T2]): (IArray[T1], IArray[T2]) = genericArrayOps(arr).partitionMap(f)
318286
def patch[U >: T: ClassTag](from: Int, other: IterableOnce[U], replaced: Int): IArray[U] = genericArrayOps(arr).patch(from, other, replaced)
319287
def permutations: Iterator[IArray[T]] = genericArrayOps(arr).permutations
320288
def prepended[U >: T: ClassTag](x: U): IArray[U] = genericArrayOps(arr).prepended(x)
321289
def prependedAll[U >: T: ClassTag](prefix: IterableOnce[U]): IArray[U] = genericArrayOps(arr).prependedAll(prefix)
322-
def product[U >: T](using math.Numeric[U]): U = arr.toSeq.product[U]
323-
def reduce[U >: T](op: (U, U) => U): U = arr.toSeq.reduce(op)
324-
def reduceLeft[U >: T](op: (U, T) => U): U = arr.toSeq.reduceLeft(op)
325-
def reduceRight[U >: T](op: (T, U) => U): U = arr.toSeq.reduceRight(op)
326290
def reverseIterator: Iterator[T] = genericArrayOps(arr).reverseIterator
327-
def sameElements[U >: T](that: IArray[U]): Boolean = arr.toSeq.sameElements(that)
328-
def sameElements[U >: T](that: IterableOnce[U]): Boolean = arr.toSeq.sameElements(that)
329291
def search[U >: T](elem: U)(using Ordering[U]): Searching.SearchResult = arr.toSeq.search(elem)
330292
def search[U >: T](elem: U, from: Int, to: Int)(using Ordering[U]): Searching.SearchResult = arr.toSeq.search(elem, from, to)
331-
def segmentLength(p: (T) => Boolean, from: Int): Int = arr.toSeq.segmentLength(p, from)
332-
def segmentLength(p: (T) => Boolean): Int = arr.toSeq.segmentLength(p)
333293
def sizeCompare(that: IArray[Any]): Int = arr.toSeq.sizeCompare(that)
334294
def sizeCompare(that: Iterable[_]): Int = arr.toSeq.sizeCompare(that)
335295
def sizeCompare(otherSize: Int): Int = genericArrayOps(arr).sizeCompare(otherSize)
336-
def sizeIs: IterableOps.SizeCompareOps = arr.toSeq.sizeIs
337296
def sliding(size: Int, step: Int = 1): Iterator[IArray[T]] = genericArrayOps(arr).sliding(size, step)
338297
def stepper[S <: Stepper[_]](using StepperShape[T, S]): S = genericArrayOps(arr).stepper[S]
339-
def sum[U >: T](using math.Numeric[U]): U = arr.toSeq.sum[U]
340298
def tails: Iterator[IArray[T]] = genericArrayOps(arr).tails
341299
def tapEach[U](f: (T) => U): IArray[T] =
342300
arr.toSeq.foreach(f)
343301
arr
344-
def to[C1](factory: Factory[T, C1]): C1 = arr.toSeq.to(factory)
345-
def toBuffer[U >: T]: Buffer[U] = arr.toSeq.toBuffer[U]
346-
def toIndexedSeq: immutable.IndexedSeq[T] = arr.toSeq.toIndexedSeq
347-
def toIterable: Iterable[T] = arr.toSeq.toIterable
348-
def toList: List[T] = arr.toSeq.toList
349-
def toSet: Set[T] = arr.toSeq.toSet
350-
def toVector: Vector[T] = arr.toSeq.toVector
351302
def unzip[T1, T2](using asPair: T => (T1, T2), ct1: ClassTag[T1], ct2: ClassTag[T2]): (IArray[T1], IArray[T2]) = genericArrayOps(arr).unzip
352303
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
353304
def updated[U >: T: ClassTag](index: Int, elem: U): IArray[U] = genericArrayOps(arr).updated(index, elem)
@@ -373,85 +324,49 @@ object IArray:
373324
extension [T, U >: T: ClassTag](x: T)
374325
def +:(arr: IArray[U]): IArray[U] = genericArrayOps(arr).prepended(x)
375326

376-
extension [T1, T2](arr: IArray[(T1, T2)])
377-
def toMap: Map[T1, T2] = arr.toSeq.toMap
378-
379-
/** Conversion from IArray to immutable.ArraySeq */
380-
extension [T](arr: IArray[T]) def toSeq: immutable.ArraySeq[T] =
381-
immutable.ArraySeq.unsafeWrapArray(arr.asInstanceOf[Array[T]])
382-
383-
/** Conversion from IArray to immutable.ArraySeq */
384-
extension [T <: AnyRef](arr: IArray[T]) def toSeq: immutable.ArraySeq[T] =
385-
immutable.ArraySeq.ofRef(arr.asInstanceOf[Array[T]])
386-
387-
/** Conversion from IArray to immutable.ArraySeq */
388-
extension (arr: IArray[Int]) def toSeq: immutable.ArraySeq[Int] =
389-
immutable.ArraySeq.ofInt(arr.asInstanceOf[Array[Int]])
390-
391-
/** Conversion from IArray to immutable.ArraySeq */
392-
extension (arr: IArray[Double]) def toSeq: immutable.ArraySeq[Double] =
393-
immutable.ArraySeq.ofDouble(arr.asInstanceOf[Array[Double]])
394-
395-
/** Conversion from IArray to immutable.ArraySeq */
396-
extension (arr: IArray[Long]) def toSeq: immutable.ArraySeq[Long] =
397-
immutable.ArraySeq.ofLong(arr.asInstanceOf[Array[Long]])
398-
399-
/** Conversion from IArray to immutable.ArraySeq */
400-
extension (arr: IArray[Float]) def toSeq: immutable.ArraySeq[Float] =
401-
immutable.ArraySeq.ofFloat(arr.asInstanceOf[Array[Float]])
402-
403-
/** Conversion from IArray to immutable.ArraySeq */
404-
extension (arr: IArray[Char]) def toSeq: immutable.ArraySeq[Char] =
405-
immutable.ArraySeq.ofChar(arr.asInstanceOf[Array[Char]])
406-
407-
/** Conversion from IArray to immutable.ArraySeq */
408-
extension (arr: IArray[Byte]) def toSeq: immutable.ArraySeq[Byte] =
409-
immutable.ArraySeq.ofByte(arr.asInstanceOf[Array[Byte]])
410-
411-
/** Conversion from IArray to immutable.ArraySeq */
412-
extension (arr: IArray[Short]) def toSeq: immutable.ArraySeq[Short] =
413-
immutable.ArraySeq.ofShort(arr.asInstanceOf[Array[Short]])
414-
415-
/** Conversion from IArray to immutable.ArraySeq */
416-
extension (arr: IArray[Boolean]) def toSeq: immutable.ArraySeq[Boolean] =
417-
immutable.ArraySeq.ofBoolean(arr.asInstanceOf[Array[Boolean]])
418-
419-
/** Conversion from IArray to immutable.ArraySeq */
420-
extension (arr: IArray[Unit]) def toSeq: immutable.ArraySeq[Unit] =
421-
immutable.ArraySeq.ofUnit(arr.asInstanceOf[Array[Unit]])
422-
423327
/** Conversion from IArray to immutable.ArraySeq */
424-
given genericWrapIArray[T](using DummyImplicit): Conversion[IArray[T], immutable.ArraySeq[T]] = _.toSeq
328+
given genericWrapIArray[T](using DummyImplicit): Conversion[IArray[T], scala.collection.immutable.ArraySeq[T]] =
329+
arr => scala.collection.immutable.ArraySeq.unsafeWrapArray(arr.asInstanceOf[Array[T]])
425330

426331
/** Conversion from IArray to immutable.ArraySeq */
427-
given genericWrapAnyRefIArray[T <: AnyRef](using DummyImplicit): Conversion[IArray[T], immutable.ArraySeq[T]] = _.toSeq
332+
given genericWrapAnyRefIArray[T <: AnyRef](using DummyImplicit): Conversion[IArray[T], scala.collection.immutable.ArraySeq[T]] =
333+
arr => scala.collection.immutable.ArraySeq.ofRef(arr.asInstanceOf[Array[T]])
428334

429335
/** Conversion from IArray to immutable.ArraySeq */
430-
given genericWrapIntIArray(using DummyImplicit): Conversion[IArray[Int], immutable.ArraySeq[Int]] = _.toSeq
336+
given genericWrapIntIArray(using DummyImplicit): Conversion[IArray[Int], scala.collection.immutable.ArraySeq[Int]] =
337+
arr => scala.collection.immutable.ArraySeq.ofInt(arr.asInstanceOf[Array[Int]])
431338

432339
/** Conversion from IArray to immutable.ArraySeq */
433-
given genericWrapDoubleIArray(using DummyImplicit): Conversion[IArray[Double], immutable.ArraySeq[Double]] = _.toSeq
340+
given genericWrapDoubleIArray(using DummyImplicit): Conversion[IArray[Double], scala.collection.immutable.ArraySeq[Double]] =
341+
arr => scala.collection.immutable.ArraySeq.ofDouble(arr.asInstanceOf[Array[Double]])
434342

435343
/** Conversion from IArray to immutable.ArraySeq */
436-
given genericWrapLongIArray(using DummyImplicit): Conversion[IArray[Long], immutable.ArraySeq[Long]] = _.toSeq
344+
given genericWrapLongIArray(using DummyImplicit): Conversion[IArray[Long], scala.collection.immutable.ArraySeq[Long]] =
345+
arr => scala.collection.immutable.ArraySeq.ofLong(arr.asInstanceOf[Array[Long]])
437346

438347
/** Conversion from IArray to immutable.ArraySeq */
439-
given genericWrapFloatIArray(using DummyImplicit): Conversion[IArray[Float], immutable.ArraySeq[Float]] = _.toSeq
348+
given genericWrapFloatIArray(using DummyImplicit): Conversion[IArray[Float], scala.collection.immutable.ArraySeq[Float]] =
349+
arr => scala.collection.immutable.ArraySeq.ofFloat(arr.asInstanceOf[Array[Float]])
440350

441351
/** Conversion from IArray to immutable.ArraySeq */
442-
given genericWrapCharIArray(using DummyImplicit): Conversion[IArray[Char], immutable.ArraySeq[Char]] = _.toSeq
352+
given genericWrapCharIArray(using DummyImplicit): Conversion[IArray[Char], scala.collection.immutable.ArraySeq[Char]] =
353+
arr => scala.collection.immutable.ArraySeq.ofChar(arr.asInstanceOf[Array[Char]])
443354

444355
/** Conversion from IArray to immutable.ArraySeq */
445-
given genericWrapByteIArray(using DummyImplicit): Conversion[IArray[Byte], immutable.ArraySeq[Byte]] = _.toSeq
356+
given genericWrapByteIArray(using DummyImplicit): Conversion[IArray[Byte], scala.collection.immutable.ArraySeq[Byte]] =
357+
arr => scala.collection.immutable.ArraySeq.ofByte(arr.asInstanceOf[Array[Byte]])
446358

447359
/** Conversion from IArray to immutable.ArraySeq */
448-
given genericWrapShortIArray(using DummyImplicit): Conversion[IArray[Short], immutable.ArraySeq[Short]] = _.toSeq
360+
given genericWrapShortIArray(using DummyImplicit): Conversion[IArray[Short], scala.collection.immutable.ArraySeq[Short]] =
361+
arr => scala.collection.immutable.ArraySeq.ofShort(arr.asInstanceOf[Array[Short]])
449362

450363
/** Conversion from IArray to immutable.ArraySeq */
451-
given genericWrapBooleanIArray(using DummyImplicit): Conversion[IArray[Boolean], immutable.ArraySeq[Boolean]] = _.toSeq
364+
given genericWrapBooleanIArray(using DummyImplicit): Conversion[IArray[Boolean], scala.collection.immutable.ArraySeq[Boolean]] =
365+
arr => scala.collection.immutable.ArraySeq.ofBoolean(arr.asInstanceOf[Array[Boolean]])
452366

453367
/** Conversion from IArray to immutable.ArraySeq */
454-
given genericWrapUnitIArray(using DummyImplicit): Conversion[IArray[Unit], immutable.ArraySeq[Unit]] = _.toSeq
368+
given genericWrapUnitIArray(using DummyImplicit): Conversion[IArray[Unit], scala.collection.immutable.ArraySeq[Unit]] =
369+
arr => scala.collection.immutable.ArraySeq.ofUnit(arr.asInstanceOf[Array[Unit]])
455370

456371
/** Convert an array into an immutable array without copying, the original array
457372
* must _not_ be mutated after this or the guaranteed immutablity of IArray will

0 commit comments

Comments
 (0)