From 47a3cbf2305d7bd98ec6c0dc4ac9c7aa0de5c7a1 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Mon, 29 Jul 2024 21:20:55 +0200 Subject: [PATCH] Combine cases of `Tuple.Zip` disjoint from `(h1 *: t1, h2 *: t2)` If we reach the second case of `Zip[T1 <: Tuple, T2 <: Tuple]`, then we know `T1` and `T2` are both disjoint from `NonEmptyTuple`. From which I believe we can conclude they are both subtypes of `EmptyTuple`. I went with `(EmptyTuple, EmptyTuple)` for the 2nd pattern, although I believe it should be equivalent to a wildcard pattern, for the same reason as described above. --- library/src/scala/Tuple.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/src/scala/Tuple.scala b/library/src/scala/Tuple.scala index c4e04359a3e1..e14588ba43a5 100644 --- a/library/src/scala/Tuple.scala +++ b/library/src/scala/Tuple.scala @@ -175,14 +175,13 @@ object Tuple { } /** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt` - * where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`, * returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct` - * where `Ct` is `EmptyTuple` if `At` or `Bt` is `EmptyTuple`, otherwise `Ct` is `Tuple`. + * where `Ct` is `EmptyTuple` if `At` and `Bt` are `EmptyTuple`, + * otherwise `Ct` is stuck as `Zip[At, Bt]`. */ type Zip[T1 <: Tuple, T2 <: Tuple] <: Tuple = (T1, T2) match { case (h1 *: t1, h2 *: t2) => (h1, h2) *: Zip[t1, t2] - case (EmptyTuple, _) => EmptyTuple - case (_, EmptyTuple) => EmptyTuple + case (EmptyTuple, EmptyTuple) => EmptyTuple } /** Converts a tuple `(F[T1], ..., F[Tn])` to `(T1, ... Tn)` */