Skip to content

Commit

Permalink
Add updated to SeqViewOps (#19798)
Browse files Browse the repository at this point in the history
Fixes #19660
  • Loading branch information
odersky authored Feb 27, 2024
2 parents d35eba0 + 3287f06 commit 42ac402
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 42ac402

Please sign in to comment.