Skip to content

Commit 14b4149

Browse files
committed
Factor out useful Tuple map type match
1 parent 33e3fe7 commit 14b4149

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ trait Implicits { self: Typer =>
719719
// TupledFunction[?, (...) => R]
720720
tupled.dropDependentRefinement.dealias.argInfos match {
721721
case tupledArgs :: funRet :: Nil =>
722-
defn.tupleTypes(tupledArgs) match {
722+
defn.tupleTypes(tupledArgs.dealias) match {
723723
case Some(funArgs) if functionTypeEqual(tupled, funArgs, funRet, fun) =>
724724
// TupledFunction[?, ((...funArgs...)) => funRet]
725725
funArgs.size

library/src-3.x/scala/Tuple.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ object Tuple {
6464
case x *: xs => S[Size[xs]]
6565
}
6666

67+
/** Converts a tuple `(T1, ..., Tn)` to `(F[T1], ..., F[Tn])` */
68+
type Map[Tup <: Tuple, F[_]] <: Tuple = Tup match {
69+
case Unit => Unit
70+
case h *: t => F[h] *: Map[t, F]
71+
}
72+
6773
/** Convert an array into a tuple of unknown arity and types */
6874
def fromArray[T](xs: Array[T]): Tuple = {
6975
val xs2 = xs match {

library/src-3.x/scala/quoted/Expr.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ package quoted {
2121
def show(implicit toolbox: Toolbox): String = toolbox.show(expr)
2222
}
2323

24-
type TupleOfExpr[Tup <: Tuple] <: Tuple = Tup match {
25-
case Unit => Unit
26-
case h *: t => Expr[h] *: TupleOfExpr[t]
27-
}
24+
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
25+
type TupleOfExpr[Tup <: Tuple] = Tuple.Map[Tup, Expr]
2826

2927
implicit class FunctionBetaReduction[F, Args <: Tuple, R](f: Expr[F]) given (tf: TupledFunction[F, Args => R]) {
3028
/** Beta-reduces the function appication. Generates the an expression only containing the body of the function */

0 commit comments

Comments
 (0)