@@ -176,7 +176,7 @@ object Tuple:
176
176
infix type ++ [X <: Tuple , + Y <: Tuple ] = Concat [X , Y ]
177
177
178
178
/** The index of `Y` in tuple `X` as a literal constant Int,
179
- * or `Size[X]` if `Y` does not occur in `X`
179
+ * or `Size[X]` if `Y` is disjoint from all element types in `X`.
180
180
*/
181
181
type IndexOf [X <: Tuple , Y ] <: Int = X match
182
182
case Y *: _ => 0
@@ -332,21 +332,22 @@ object Tuple:
332
332
runtime.Tuples .fromProduct(product)
333
333
334
334
extension [X <: Tuple ](inline x : X )
335
+ // Note the two methods are not equivalent to using `constValue`,
336
+ // since they also allow cases unknown at compiletime.
337
+ // Also note it would be unsound to use a type parameter for `y` in the type level
338
+ // operations, since they are rightfully not covariant in their second parameter.
335
339
336
340
/** The index (starting at 0) of the first occurrence of y.type in the type `X` of `x`
337
341
* or Size[X] if no such element exists.
338
342
*/
339
- transparent inline def indexOf (y : Any ): Int = constValue[IndexOf [X , y.type ]]
343
+ inline def indexOf (y : Any ): IndexOf [X , y.type ] =
344
+ x.productIterator.indexOf(y).asInstanceOf [IndexOf [X , y.type ]]
340
345
341
346
/** A boolean indicating whether there is an element `y.type` in the type `X` of `x` */
342
- // Note this isn't equivalent to `constValue[Contains[X, y.type]]`
343
- // since it also accepts cases unknown at compiletime.
344
- // Also note it would be unsound to use a type parameter for `y` in the
345
- // type level `Contains`, since it is rightfully not covariant in `Y`.
346
347
inline def contains (y : Any ): Contains [X , y.type ] =
347
348
x.productIterator.contains(y).asInstanceOf [Contains [X , y.type ]]
348
349
349
- // TODO containsType ?
350
+ // TODO indexOfType & containsType ?
350
351
351
352
end extension
352
353
0 commit comments