Skip to content

Commit

Permalink
Add an infix shorthand for Tuple.Append
Browse files Browse the repository at this point in the history
Addressing #19175
  • Loading branch information
EugeneFlesselle committed Nov 7, 2024
1 parent 4ae5d61 commit 74349e8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ sealed trait Tuple extends Product {
runtime.Tuples.toIArray(this)

/** Return a copy of `this` tuple with an element appended */
inline def :* [This >: this.type <: Tuple, L] (x: L): Append[This, L] =
runtime.Tuples.append(x, this).asInstanceOf[Append[This, L]]
inline def :* [This >: this.type <: Tuple, L] (x: L): This :* L =
runtime.Tuples.append(x, this).asInstanceOf[This :* L]

/** Return a new tuple by prepending the element to `this` tuple.
* This operation is O(this.size)
Expand Down Expand Up @@ -94,6 +94,9 @@ object Tuple {
case x *: xs => x *: Append[xs, Y]
}

/** An infix shorthand for `Append[X, Y]` */
infix type :*[X <: Tuple, Y] = Append[X, Y]

/** Type of the head of a tuple */
type Head[X <: Tuple] = X match {
case x *: _ => x
Expand Down

0 comments on commit 74349e8

Please sign in to comment.