File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,18 @@ object Tuple {
120
120
case h *: t => Concat [F [h], FlatMap [t, F ]]
121
121
}
122
122
123
+ /**
124
+ * Use this type to widen a self-type to a tuple. E.g.
125
+ * ```
126
+ * val x: (1, 3) = (1, 3)
127
+ * val y: Widen[x.type] = x
128
+ * ```
129
+ */
130
+ type Widen [Tup <: Tuple ] <: Tuple = Tup match {
131
+ case EmptyTuple => EmptyTuple
132
+ case h *: t => h *: t
133
+ }
134
+
123
135
/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
124
136
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
125
137
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct`
Original file line number Diff line number Diff line change @@ -42,13 +42,13 @@ package object compiletime {
42
42
43
43
inline def constValue [T ]: T = ???
44
44
45
- inline def constValueTuple [T <: Tuple ]: T =
45
+ inline def constValueTuple [T <: Tuple ]: Tuple . Widen [ T ] =
46
46
val res =
47
47
inline erasedValue[T ] match
48
48
case _ : EmptyTuple => EmptyTuple
49
49
case _ : (t *: ts) => constValue[t] *: constValueTuple[ts]
50
50
end match
51
- res.asInstanceOf [T ]
51
+ res.asInstanceOf [Tuple . Widen [ T ] ]
52
52
end constValueTuple
53
53
54
54
/** Summons first given matching one of the listed cases. E.g. in
@@ -83,13 +83,13 @@ package object compiletime {
83
83
* @tparam T the tuple containing the types of the values to be summoned
84
84
* @return the given values typed as elements of the tuple
85
85
*/
86
- inline def summonAll [T <: Tuple ]: T =
86
+ inline def summonAll [T <: Tuple ]: Tuple . Widen [ T ] =
87
87
val res =
88
88
inline erasedValue[T ] match
89
89
case _ : EmptyTuple => EmptyTuple
90
90
case _ : (t *: ts) => summonInline[t] *: summonAll[ts]
91
91
end match
92
- res.asInstanceOf [T ]
92
+ res.asInstanceOf [Tuple . Widen [ T ] ]
93
93
end summonAll
94
94
95
95
/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
You can’t perform that action at this time.
0 commit comments