From a6b2a2c7b11f8d07797a6d80f8fa73ad27e13734 Mon Sep 17 00:00:00 2001 From: ghik Date: Tue, 25 Jun 2019 10:52:45 +0200 Subject: [PATCH] added apply, unapplySeq and newBuilder to ArraySeq companion --- .../collection/compat/immutable/ArraySeq.scala | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala index 5dcb4e9f..ff299818 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala @@ -58,7 +58,7 @@ abstract class ArraySeq[+T] extends AbstractSeq[T] with IndexedSeq[T] { /** Creates new builder for this collection ==> move to subclasses */ override protected[this] def newBuilder: Builder[T, ArraySeq[T]] = - new WrappedArrayBuilder[T](elemTag).mapResult(w => ArraySeq.unsafeWrapArray(w.array)) + ArraySeq.newBuilder[T](elemTag) } @@ -69,6 +69,17 @@ object ArraySeq { private val EmptyArraySeq = new ofRef[AnyRef](new Array[AnyRef](0)) def empty[T <: AnyRef]: ArraySeq[T] = EmptyArraySeq.asInstanceOf[ArraySeq[T]] + def newBuilder[T](implicit elemTag: ClassTag[T]): Builder[T, ArraySeq[T]] = + new WrappedArrayBuilder[T](elemTag).mapResult(w => unsafeWrapArray(w.array)) + + def apply[T](elems: T*)(implicit elemTag: ClassTag[T]): ArraySeq[T] = { + val b = newBuilder[T] + b ++= elems + b.result() + } + + def unapplySeq[T](seq: ArraySeq[T]): Some[ArraySeq[T]] = Some(seq) + /** * Wrap an existing `Array` into an `ArraySeq` of the proper primitive specialization type * without copying.