@@ -22,13 +22,13 @@ sealed trait Tuple extends Product:
22
22
runtime.Tuples .toIArray(this )
23
23
24
24
/** Return a copy of `this` tuple with an element appended */
25
- inline def :* [This >: this .type <: Tuple , L ] (x : L ): Append [This , L ] =
25
+ inline def :* [This >: this .type <: Tuple , L ](x : L ): Append [This , L ] =
26
26
runtime.Tuples .append(x, this ).asInstanceOf [Append [This , L ]]
27
27
28
28
/** Return a new tuple by prepending the element to `this` tuple.
29
29
* This operation is O(this.size)
30
30
*/
31
- inline def *: [H , This >: this .type <: Tuple ] (x : H ): H *: This =
31
+ inline def *: [H , This >: this .type <: Tuple ](x : H ): H *: This =
32
32
runtime.Tuples .cons(x, this ).asInstanceOf [H *: This ]
33
33
34
34
/** Return a new tuple by concatenating `this` tuple with `that` tuple.
@@ -104,14 +104,13 @@ object Tuple:
104
104
/** The size of a tuple, represented as a literal constant subtype of Int */
105
105
type Size [X <: Tuple ] <: Int = X match
106
106
case EmptyTuple => 0
107
- case x *: xs => S [Size [xs]]
107
+ case _ *: xs => S [Size [xs]]
108
108
109
109
/** The type of the element at position N in the tuple X */
110
110
type Elem [X <: Tuple , N <: Int ] = X match
111
- case x *: xs =>
112
- N match
113
- case 0 => x
114
- case S [n1] => Elem [xs, n1]
111
+ case x *: xs => N match
112
+ case 0 => x
113
+ case S [n1] => Elem [xs, n1]
115
114
116
115
/** The type of the first element of a tuple */
117
116
// Only bounded by `<: Tuple` not `<: NonEmptyTuple`
@@ -134,8 +133,7 @@ object Tuple:
134
133
/** The type of the initial part of a tuple without its last element */
135
134
type Init [X <: Tuple ] <: Tuple = X match
136
135
case _ *: EmptyTuple => EmptyTuple
137
- case x *: xs =>
138
- x *: Init [xs]
136
+ case x *: xs => x *: Init [xs]
139
137
140
138
/** The type of the tuple consisting of the first `N` elements of `X`,
141
139
* or all elements if `N` exceeds `Size[X]`.
@@ -149,27 +147,24 @@ object Tuple:
149
147
/** The type of the tuple consisting of all elements of `X` except the first `N` ones,
150
148
* or no elements if `N` exceeds `Size[X]`.
151
149
*/
152
- type Drop [X <: Tuple , N <: Int ] <: Tuple = N match {
150
+ type Drop [X <: Tuple , N <: Int ] <: Tuple = N match
153
151
case 0 => X
154
- case S [n1] => X match {
152
+ case S [n1] => X match
155
153
case EmptyTuple => EmptyTuple
156
- case x *: xs => Drop [xs, n1]
157
- }
158
- }
154
+ case _ *: xs => Drop [xs, n1]
159
155
160
156
/** The pair type `(Take(X, N), Drop[X, N]). */
161
157
type Split [X <: Tuple , N <: Int ] = (Take [X , N ], Drop [X , N ])
162
158
163
159
/** Type of a tuple with an element appended */
164
- type Append [X <: Tuple , Y ] <: NonEmptyTuple = X match {
160
+ type Append [X <: Tuple , Y ] <: NonEmptyTuple = X match
165
161
case EmptyTuple => Y *: EmptyTuple
166
162
case x *: xs => x *: Append [xs, Y ]
167
- }
168
163
169
164
/** Type of the concatenation of two tuples `X` and `Y` */
170
165
type Concat [X <: Tuple , + Y <: Tuple ] <: Tuple = X match
171
166
case EmptyTuple => Y
172
- case x1 *: xs1 => x1 *: Concat [xs1 , Y ]
167
+ case x *: xs => x *: Concat [xs , Y ]
173
168
174
169
/** An infix shorthand for `Concat[X, Y]` */
175
170
infix type ++ [X <: Tuple , + Y <: Tuple ] = Concat [X , Y ]
@@ -179,27 +174,27 @@ object Tuple:
179
174
*/
180
175
type IndexOf [X <: Tuple , Y ] <: Int = X match
181
176
case Y *: _ => 0
182
- case x *: xs => S [IndexOf [xs, Y ]]
177
+ case _ *: xs => S [IndexOf [xs, Y ]]
183
178
case EmptyTuple => 0
184
179
185
180
/** Fold a tuple `(T1, ..., Tn)` into `F[T1, F[... F[Tn, Z]...]]]` */
186
- type Fold [Tup <: Tuple , Z , F [_, _]] = Tup match
181
+ type Fold [X <: Tuple , Z , F [_, _]] = X match
187
182
case EmptyTuple => Z
188
- case h *: t => F [h , Fold [t , Z , F ]]
183
+ case x *: xs => F [x , Fold [xs , Z , F ]]
189
184
190
185
/** The type of tuple `X` mapped with the type-level function `F`.
191
186
* If `X = (T1, ..., Ti)` then `Map[X, F] = `(F[T1], ..., F[Ti])`.
192
187
*/
193
- type Map [Tup <: Tuple , F [_ <: Union [Tup ]]] <: Tuple = Tup match
188
+ type Map [X <: Tuple , F [_ <: Union [X ]]] <: Tuple = X match
194
189
case EmptyTuple => EmptyTuple
195
- case h *: t => F [h ] *: Map [t , F ]
190
+ case x *: xs => F [x ] *: Map [xs , F ]
196
191
197
192
/** The type of tuple `X` flat-mapped with the type-level function `F`.
198
193
* If `X = (T1, ..., Ti)` then `FlatMap[X, F] = `F[T1] ++ ... ++ F[Ti]`
199
194
*/
200
- type FlatMap [Tup <: Tuple , F [_ <: Union [Tup ]] <: Tuple ] <: Tuple = Tup match
195
+ type FlatMap [X <: Tuple , F [_ <: Union [X ]] <: Tuple ] <: Tuple = X match
201
196
case EmptyTuple => EmptyTuple
202
- case h *: t => Concat [F [h ], FlatMap [t , F ]]
197
+ case x *: xs => Concat [F [x ], FlatMap [xs , F ]]
203
198
// TODO: implement term level analogue
204
199
205
200
/** The type of the tuple consisting of all elements of tuple `X` that have types
@@ -217,9 +212,9 @@ object Tuple:
217
212
*/
218
213
type Filter [X <: Tuple , P [_] <: Boolean ] <: Tuple = X match
219
214
case EmptyTuple => EmptyTuple
220
- case h *: t => P [h ] match
221
- case true => h *: Filter [t , P ]
222
- case false => Filter [t , P ]
215
+ case x *: xs => P [x ] match
216
+ case true => x *: Filter [xs , P ]
217
+ case false => Filter [xs , P ]
223
218
224
219
/** A tuple consisting of those indices `N` of tuple `X` where the predicate `P`
225
220
* is true for `Elem[X, N]`. Indices are type level values <: Int.
@@ -242,17 +237,16 @@ object Tuple:
242
237
* ```
243
238
* @syntax markdown
244
239
*/
245
- type Zip [T1 <: Tuple , T2 <: Tuple ] <: Tuple = (T1 , T2 ) match
246
- case (h1 *: t1, h2 *: t2 ) => (h1, h2 ) *: Zip [t1, t2 ]
240
+ type Zip [X <: Tuple , Y <: Tuple ] <: Tuple = (X , Y ) match
241
+ case (x *: xs, y *: ys ) => (x, y ) *: Zip [xs, ys ]
247
242
case (EmptyTuple , _) => EmptyTuple
248
243
case (_, EmptyTuple ) => EmptyTuple
249
244
case _ => Tuple
250
245
251
246
/** Converts a tuple `(F[T1], ..., F[Tn])` to `(T1, ... Tn)` */
252
- type InverseMap [X <: Tuple , F [_]] <: Tuple = X match {
253
- case F [x] *: t => x *: InverseMap [t , F ]
247
+ type InverseMap [X <: Tuple , F [_]] <: Tuple = X match
248
+ case F [x] *: xs => x *: InverseMap [xs , F ]
254
249
case EmptyTuple => EmptyTuple
255
- }
256
250
257
251
/** Implicit evidence. IsMappedBy[F][X] is present in the implicit scope iff
258
252
* X is a tuple for which each element's type is constructed via `F`. E.g.
@@ -280,18 +274,17 @@ object Tuple:
280
274
*/
281
275
type Contains [X <: Tuple , Y ] <: Boolean = X match
282
276
case Y *: _ => true
283
- case x *: xs => Contains [xs, Y ]
277
+ case _ *: xs => Contains [xs, Y ]
284
278
case EmptyTuple => false
285
279
286
280
/** A type level Boolean indicating whether the type `Y` contains
287
281
* none of the elements of `X`.
288
282
* @pre The elements of `X` and `Y` are assumed to be singleton types
289
283
*/
290
284
type Disjoint [X <: Tuple , Y <: Tuple ] <: Boolean = X match
291
- case x *: xs =>
292
- Contains [Y , x] match
293
- case true => false
294
- case false => Disjoint [xs, Y ]
285
+ case x *: xs => Contains [Y , x] match
286
+ case true => false
287
+ case false => Disjoint [xs, Y ]
295
288
case EmptyTuple => true
296
289
297
290
/** Empty tuple */
0 commit comments