@@ -30,7 +30,7 @@ object NamedTuple:
3030
3131 export NamedTupleDecomposition .{
3232 Names , DropNames ,
33- apply , size , init , last , tail , take , drop , splitAt , ++ , map , reverse , zip , toList , toArray , toIArray
33+ apply , size , init , head , last , tail , take , drop , splitAt , ++ , map , reverse , zip , toList , toArray , toIArray
3434 }
3535
3636 extension [N <: Tuple , V <: Tuple ](x : NamedTuple [N , V ])
@@ -43,9 +43,6 @@ object NamedTuple:
4343 // and should be reverted, just like NonEmptyList is also appealing at first, but a bad idea
4444 // in the end.
4545
46- /** The first element value of this tuple */
47- inline def head : Tuple .Elem [V , 0 ] = x.apply(0 )
48-
4946 // inline def :* [L] (x: L): NamedTuple[Append[N, ???], Append[V, L] = ???
5047 // inline def *: [H] (x: H): NamedTuple[??? *: N], H *: V] = ???
5148
@@ -142,13 +139,14 @@ object NamedTupleDecomposition:
142139 extension [N <: Tuple , V <: Tuple ](x : NamedTuple [N , V ])
143140 /** The value (without the name) at index `n` of this tuple */
144141 inline def apply (n : Int ): Tuple .Elem [V , n.type ] =
145- inline x.toTuple match
146- case tup : NonEmptyTuple => tup(n).asInstanceOf [Tuple .Elem [V , n.type ]]
147- case tup => tup.productElement(n).asInstanceOf [Tuple .Elem [V , n.type ]]
142+ x.toTuple.apply(n).asInstanceOf [Tuple .Elem [V , n.type ]]
148143
149144 /** The number of elements in this tuple */
150145 inline def size : Tuple .Size [V ] = x.toTuple.size
151146
147+ /** The first element value of this tuple */
148+ inline def head : Tuple .Elem [V , 0 ] = apply(0 )
149+
152150 /** The last element value of this tuple */
153151 inline def last : Tuple .Last [V ] = apply(size - 1 ).asInstanceOf [Tuple .Last [V ]]
154152
0 commit comments