From 74349e85a7450e6914b1bbc2d803edf341d23395 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Mon, 29 Apr 2024 11:32:05 +0200 Subject: [PATCH 1/2] Add an infix shorthand for `Tuple.Append` Addressing #19175 --- library/src/scala/Tuple.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/src/scala/Tuple.scala b/library/src/scala/Tuple.scala index 8074fe3664e5..343194d06488 100644 --- a/library/src/scala/Tuple.scala +++ b/library/src/scala/Tuple.scala @@ -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) @@ -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 From 4e47edfa789ca8f4c2175ebfb95dc43f09e29aa3 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Mon, 29 Jul 2024 10:51:38 +0200 Subject: [PATCH 2/2] Add an infix shorthand for `Tuple.Concat` Addressing #19175 --- library/src/scala/Tuple.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/src/scala/Tuple.scala b/library/src/scala/Tuple.scala index 343194d06488..bf05b617a51d 100644 --- a/library/src/scala/Tuple.scala +++ b/library/src/scala/Tuple.scala @@ -34,8 +34,8 @@ sealed trait Tuple extends Product { /** Return a new tuple by concatenating `this` tuple with `that` tuple. * This operation is O(this.size + that.size) */ - inline def ++ [This >: this.type <: Tuple](that: Tuple): Concat[This, that.type] = - runtime.Tuples.concat(this, that).asInstanceOf[Concat[This, that.type]] + inline def ++ [This >: this.type <: Tuple](that: Tuple): This ++ that.type = + runtime.Tuples.concat(this, that).asInstanceOf[This ++ that.type] /** Return the size (or arity) of the tuple */ inline def size[This >: this.type <: Tuple]: Size[This] = @@ -126,6 +126,9 @@ object Tuple { case x1 *: xs1 => x1 *: Concat[xs1, Y] } + /** An infix shorthand for `Concat[X, Y]` */ + infix type ++[X <: Tuple, +Y <: Tuple] = Concat[X, Y] + /** Type of the element at position N in the tuple X */ type Elem[X <: Tuple, N <: Int] = X match { case x *: xs =>