Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added apply, unapplySeq and newBuilder to ArraySeq companion #227

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

Expand All @@ -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.
Expand Down