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

Add updated to SeqViewOps #19798

Merged
merged 1 commit into from
Feb 27, 2024
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
11 changes: 11 additions & 0 deletions scala2-library-cc/src/scala/collection/SeqView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
def length: Int
def apply(x: Int): A
def appended[B >: A](elem: B): CC[B]^{this}
def updated[B >: A](index: Int, elem: B): CC[B]^{this}
def prepended[B >: A](elem: B): CC[B]^{this}
def reverse: C^{this}
def sorted[B >: A](implicit ord: Ordering[B]): C^{this}
Expand All @@ -44,6 +45,16 @@ trait SeqView[+A] extends SeqViewOps[A, View, View[A]] with View[A] {

override def map[B](f: A => B): SeqView[B]^{this, f} = new SeqView.Map(this, f)
override def appended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Appended(this, elem)

// Copied from SeqOps. This is needed due to the change of class hierarchy in stdlib.
// See #19660.
override def updated[B >: A](index: Int, elem: B): View[B]^{this} = {
if(index < 0) throw new IndexOutOfBoundsException(index.toString)
val k = knownSize
if(k >= 0 && index >= k) throw new IndexOutOfBoundsException(index.toString)
iterableFactory.from(new View.Updated(this, index, elem))
}

override def prepended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Prepended(elem, this)
override def reverse: SeqView[A]^{this} = new SeqView.Reverse(this)
override def take(n: Int): SeqView[A]^{this} = new SeqView.Take(this, n)
Expand Down
Loading