File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,18 @@ object Tuple {
125
125
case h *: t => Concat [F [h], FlatMap [t, F ]]
126
126
}
127
127
128
+ /**
129
+ * Use this type to widen a self-type to a tuple. E.g.
130
+ * ```
131
+ * val x: (1, 3) = (1, 3)
132
+ * val y: Widen[x.type] = x
133
+ * ```
134
+ */
135
+ type Widen [Tup <: Tuple ] <: Tuple = Tup match {
136
+ case EmptyTuple => EmptyTuple
137
+ case h *: t => h *: t
138
+ }
139
+
128
140
/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
129
141
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
130
142
* 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