Skip to content

Commit

Permalink
Move more methods from SeqOps to SeqViewOps
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Mar 4, 2024
1 parent a28b792 commit 7df8539
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
16 changes: 8 additions & 8 deletions scala2-library-cc/src/scala/collection/Seq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
*
* @return a new $coll consisting of all the elements of this $coll without duplicates.
*/
def distinct: C = distinctBy(identity)
override def distinct: C = distinctBy(identity)

/** Selects all the elements of this $coll ignoring the duplicates as determined by `==` after applying
* the transforming function `f`.
Expand All @@ -215,7 +215,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* @tparam B the type of the elements after being transformed by `f`
* @return a new $coll consisting of all the elements of this $coll without duplicates.
*/
def distinctBy[B](f: A -> B): C = fromSpecific(new View.DistinctBy(this, f))
override def distinctBy[B](f: A -> B): C = fromSpecific(new View.DistinctBy(this, f))

/** Returns new $coll with elements in reversed order.
*
Expand Down Expand Up @@ -293,7 +293,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* all elements of this $coll followed by the minimal number of occurrences of `elem` so
* that the resulting collection has a length of at least `len`.
*/
def padTo[B >: A](len: Int, elem: B): CC[B] = iterableFactory.from(new View.PadTo(this, len, elem))
override def padTo[B >: A](len: Int, elem: B): CC[B] = iterableFactory.from(new View.PadTo(this, len, elem))

/** Computes the length of the longest segment that starts from the first element
* and whose elements all satisfy some predicate.
Expand Down Expand Up @@ -544,7 +544,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* // List(b, b, a)
* }}}
*/
def permutations: Iterator[C] =
override def permutations: Iterator[C] =
if (isEmpty) Iterator.single(coll)
else new PermutationsItr

Expand Down Expand Up @@ -585,7 +585,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* // List(b, a)
* }}}
*/
def combinations(n: Int): Iterator[C] =
override def combinations(n: Int): Iterator[C] =
if (n < 0 || n > size) Iterator.empty
else new CombinationsItr(n)

Expand Down Expand Up @@ -759,7 +759,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* List("Bobby", "Bob", "John", "Steve", "Tom")
* }}}
*/
def sortWith(lt: (A, A) => Boolean): C = sorted(Ordering.fromLessThan(lt))
override def sortWith(lt: (A, A) => Boolean): C = sorted(Ordering.fromLessThan(lt))

/** Sorts this $coll according to the Ordering which results from transforming
* an implicitly given Ordering with a transformation function.
Expand All @@ -786,7 +786,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* res0: Array[String] = Array(The, dog, fox, the, lazy, over, brown, quick, jumped)
* }}}
*/
def sortBy[B](f: A => B)(implicit ord: Ordering[B]): C = sorted(ord on f)
override def sortBy[B](f: A => B)(implicit ord: Ordering[B]): C = sorted(ord on f)

/** Produces the range of all indices of this sequence.
* $willForceEvaluation
Expand Down Expand Up @@ -944,7 +944,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* except that `replaced` elements starting from `from` are replaced
* by all the elements of `other`.
*/
def patch[B >: A](from: Int, other: IterableOnce[B]^, replaced: Int): CC[B] =
override def patch[B >: A](from: Int, other: IterableOnce[B]^, replaced: Int): CC[B] =
iterableFactory.from(new View.Patched(this, from, other, replaced))
.unsafeAssumePure // assume pure OK since iterableFactory.from is eager for Seq

Expand Down
28 changes: 27 additions & 1 deletion scala2-library-cc/src/scala/collection/SeqView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,38 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
def reverse: C^{this}
def sorted[B >: A](implicit ord: Ordering[B]): C^{this}

// Placeholder implementation for that method in SeqOps.
// Placeholder implementations for the corresponding methods in SeqOps.
// This is needed due to the change in the class hierarchy in cc stdlib.
// See #19660 and #19819.
// -------------------
def updated[B >: A](index: Int, elem: B): CC[B]^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def padTo[B >: A](len: Int, elem: B): CC[B]^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def patch[B >: A](from: Int, other: IterableOnce[B]^, replaced: Int): CC[B]^{this, other} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def combinations(n: Int): Iterator[C^{this}]^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def sortBy[B](f: A => B)(implicit ord: Ordering[B]): C^{this, f} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def sortWith(lt: (A, A) => Boolean): C^{this, lt} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def permutations: Iterator[C^{this}]^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def distinct: C^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
def distinctBy[B](f: A -> B): C^{this} =
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
???
// -------------------

def reverseIterator: Iterator[A]^{this} = reversed.iterator
}
Expand Down

0 comments on commit 7df8539

Please sign in to comment.