Skip to content

Commit

Permalink
Remove changes from src-non-bootstrapped/scala/Tuple.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Dec 8, 2023
1 parent 7e6475a commit 8920b83
Showing 1 changed file with 0 additions and 104 deletions.
104 changes: 0 additions & 104 deletions library/src-non-bootstrapped/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,108 +89,6 @@ sealed trait Tuple extends Product {

object Tuple {

// TODO should it be `extension [H](x: H) def *:(tail: Tuple): H *: tuple.type` ?
extension [H, Tail <: Tuple](x: H)
/** Return a new tuple by prepending the element to `tail` tuple.
* This operation is O(tail.size)
*/
def *:(tail: Tail): H *: Tail = runtime.Tuples.cons(x, tail).asInstanceOf[H *: Tail]

extension [This <: Tuple](tuple: This)
/** Get the head of this tuple */
def head: Head[This] & Head[tuple.type] =
runtime.Tuples.apply(tuple, 0).asInstanceOf[Head[This] & Head[tuple.type]]

/** Get the tail of this tuple.
* This operation is O(tuple.size)
*/
def tail: Tail[This] & Tail[tuple.type] =
runtime.Tuples.tail(tuple).asInstanceOf[Tail[This] & Tail[tuple.type]]

/** Return the size (or arity) of the tuple */
def size: Size[This] & Size[tuple.type] =
runtime.Tuples.size(tuple).asInstanceOf[Size[This] & Size[tuple.type]]

/** Get the i-th element of this tuple.
* Equivalent to productElement but with a precise return type.
*/
def apply(n: Int): Elem[This, n.type] & Elem[tuple.type, n.type] =
runtime.Tuples.apply(tuple, n).asInstanceOf[Elem[This, n.type] & Elem[tuple.type, n.type]]

/** Get the initial part of the tuple without its last element */
def init: Init[This] & Init[tuple.type] =
runtime.Tuples.init(tuple).asInstanceOf[Init[This] & Init[tuple.type]]

/** Get the last of this tuple */
def last: Last[This] & Last[tuple.type] =
runtime.Tuples.last(tuple).asInstanceOf[Last[This] & Last[tuple.type]]

/** Return a copy of `tuple` with an element appended */
def :*[X] (x: X): Append[This, X] & Append[tuple.type, X] =
runtime.Tuples.append(x, tuple).asInstanceOf[Append[This, X] & Append[tuple.type, X]]

/** Return a new tuple by concatenating `this` tuple with `that` tuple.
* This operation is O(this.size + that.size)
*/
def ++(that: Tuple): Concat[This, that.type] & Concat[tuple.type, that.type] =
runtime.Tuples.concat(tuple, that).asInstanceOf[Concat[This, that.type] & Concat[tuple.type, that.type]]

/** Given a tuple `(a1, ..., am)`, returns the reversed tuple `(am, ..., a1)`
* consisting all its elements.
*/
@experimental
def reverse: Reverse[This] & Reverse[tuple.type] =
runtime.Tuples.reverse(tuple).asInstanceOf[Reverse[This] & Reverse[tuple.type]]

/** Given two tuples, `(a1, ..., an)` and `(a1, ..., an)`, returns a tuple
* `((a1, b1), ..., (an, bn))`. If the two tuples have different sizes,
* the extra elements of the larger tuple will be disregarded.
* The result is typed as `((A1, B1), ..., (An, Bn))` if at least one of the
* tuple types has a `EmptyTuple` tail. Otherwise the result type is
* `(A1, B1) *: ... *: (Ai, Bi) *: Tuple`
*/
// TODO change signature? def zip[That <: Tuple](that: That): Zip[This, tuple.type] & Zip[tuple.type, tuple.type] =
def zip[That <: Tuple](that: That): Zip[This, That] & Zip[tuple.type, That] =
runtime.Tuples.zip(tuple, that).asInstanceOf[Zip[This, That] & Zip[tuple.type, That]]

/** Called on a tuple `(a1, ..., an)`, returns a new tuple `(f(a1), ..., f(an))`.
* The result is typed as `(F[A1], ..., F[An])` if the tuple type is fully known.
* If the tuple is of the form `a1 *: ... *: Tuple` (that is, the tail is not known
* to be the cons type.
*/
def map[F[_]](f: [t] => t => F[t]): Map[This, F] & Map[tuple.type, F] =
runtime.Tuples.map(tuple, f).asInstanceOf[Map[This, F] & Map[tuple.type, F]]

/** Given a tuple `(a1, ..., am)`, returns the tuple `(a1, ..., an)` consisting
* of its first n elements.
*/
def take(n: Int): Take[This, n.type] & Take[tuple.type, n.type] =
runtime.Tuples.take(tuple, n).asInstanceOf[Take[This, n.type] & Take[tuple.type, n.type]]

/** Given a tuple `(a1, ..., am)`, returns the tuple `(an+1, ..., am)` consisting
* all its elements except the first n ones.
*/
def drop(n: Int): Drop[This, n.type] & Take[tuple.type, n.type] =
runtime.Tuples.drop(tuple, n).asInstanceOf[Drop[This, n.type] & Take[tuple.type, n.type]]

/** Given a tuple `(a1, ..., am)`, returns a pair of the tuple `(a1, ..., an)`
* consisting of the first n elements, and the tuple `(an+1, ..., am)` consisting
* of the remaining elements.
*/
def splitAt(n: Int): Split[This, n.type] & Split[tuple.type, n.type] =
runtime.Tuples.splitAt(tuple, n).asInstanceOf[Split[This, n.type] & Split[tuple.type, n.type]]

/** Create a copy of this tuple as a List */
def toList: List[Union[This]] & List[Union[tuple.type]] =
tuple.productIterator.toList.asInstanceOf[List[Union[This]] & List[Union[tuple.type]]]

extension (tuple: Tuple)
/** Create a copy of this tuple as an Array */
def toArray: Array[AnyRef] = runtime.Tuples.toArray(tuple)

/** Create a copy of this tuple as an IArray */
def toIArray: IArray[AnyRef] = runtime.Tuples.toIArray(tuple)

/** Type of a tuple with an element appended */
type Append[X <: Tuple, Y] <: NonEmptyTuple = X match {
case EmptyTuple => Y *: EmptyTuple
Expand All @@ -200,7 +98,6 @@ object Tuple {
/** Type of the head of a tuple */
type Head[X <: Tuple] = X match {
case x *: _ => x
case EmptyTuple => Nothing
}

/** Type of the initial part of the tuple without its last element */
Expand All @@ -213,7 +110,6 @@ object Tuple {
/** Type of the tail of a tuple */
type Tail[X <: Tuple] <: Tuple = X match {
case _ *: xs => xs
case EmptyTuple => Nothing
}

/** Type of the last element of a tuple */
Expand Down

0 comments on commit 8920b83

Please sign in to comment.