Skip to content

Commit fd8475c

Browse files
committed
added apply, unapplySeq and newBuilder to ArraySeq companion
1 parent a65de8d commit fd8475c

File tree

1 file changed

+15
-1
lines changed
  • compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable

1 file changed

+15
-1
lines changed

compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/ArraySeq.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class ArraySeq[+T] extends AbstractSeq[T] with IndexedSeq[T] {
5858
/** Creates new builder for this collection ==> move to subclasses
5959
*/
6060
override protected[this] def newBuilder: Builder[T, ArraySeq[T]] =
61-
new WrappedArrayBuilder[T](elemTag).mapResult(w => ArraySeq.unsafeWrapArray(w.array))
61+
ArraySeq.newBuilder[T](elemTag)
6262

6363
}
6464

@@ -69,6 +69,20 @@ object ArraySeq {
6969
private val EmptyArraySeq = new ofRef[AnyRef](new Array[AnyRef](0))
7070
def empty[T <: AnyRef]: ArraySeq[T] = EmptyArraySeq.asInstanceOf[ArraySeq[T]]
7171

72+
def newBuilder[T](implicit elemTag: ClassTag[T]): Builder[T, ArraySeq[T]] =
73+
new WrappedArrayBuilder[T](elemTag).mapResult(w => unsafeWrapArray(w.array))
74+
75+
def apply[T](elems: T*)(implicit elemTag: ClassTag[T]): ArraySeq[T] = {
76+
if (elems.isEmpty) empty[T]
77+
else {
78+
val b = newBuilder[T]
79+
b ++= elems
80+
b.result()
81+
}
82+
}
83+
84+
def unapplySeq[T](seq: ArraySeq[T]): Some[Seq[T]] = Some(seq)
85+
7286
/**
7387
* Wrap an existing `Array` into an `ArraySeq` of the proper primitive specialization type
7488
* without copying.

0 commit comments

Comments
 (0)