Skip to content

Commit 97e552b

Browse files
authored
Merge pull request #227 from ghik/issue/222
Added apply, unapplySeq and newBuilder to ArraySeq companion
2 parents d60782e + a6b2a2c commit 97e552b

File tree

1 file changed

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

1 file changed

+12
-1
lines changed

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

Lines changed: 12 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,17 @@ 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+
val b = newBuilder[T]
77+
b ++= elems
78+
b.result()
79+
}
80+
81+
def unapplySeq[T](seq: ArraySeq[T]): Some[ArraySeq[T]] = Some(seq)
82+
7283
/**
7384
* Wrap an existing `Array` into an `ArraySeq` of the proper primitive specialization type
7485
* without copying.

0 commit comments

Comments
 (0)