@@ -46,13 +46,15 @@ object NamedTuple:
46
46
inline def head : Tuple .Elem [V , 0 ] = apply(0 )
47
47
48
48
/** The tuple consisting of all elements of this tuple except the first one */
49
- inline def tail : Tuple .Drop [V , 1 ] = toTuple.drop(1 )
49
+ inline def tail : NamedTuple [Tuple .Tail [N ], Tuple .Tail [V ]] =
50
+ toTuple.drop(1 ).asInstanceOf [NamedTuple [Tuple .Tail [N ], Tuple .Tail [V ]]]
50
51
51
52
/** The last element value of this tuple */
52
53
inline def last : Tuple .Last [V ] = apply(size - 1 ).asInstanceOf [Tuple .Last [V ]]
53
54
54
55
/** The tuple consisting of all elements of this tuple except the last one */
55
- inline def init : Tuple .Init [V ] = toTuple.take(size - 1 ).asInstanceOf [Tuple .Init [V ]]
56
+ inline def init : NamedTuple [Tuple .Init [N ], Tuple .Init [V ]] =
57
+ toTuple.take(size - 1 ).asInstanceOf [NamedTuple [Tuple .Init [N ], Tuple .Init [V ]]]
56
58
57
59
/** The tuple consisting of the first `n` elements of this tuple, or all
58
60
* elements if `n` exceeds `size`.
@@ -67,7 +69,11 @@ object NamedTuple:
67
69
toTuple.drop(n)
68
70
69
71
/** The tuple `(x.take(n), x.drop(n))` */
70
- inline def splitAt (n : Int ): NamedTuple [Tuple .Split [N , n.type ], Tuple .Split [V , n.type ]] =
72
+ inline def splitAt (n : Int ):
73
+ (NamedTuple [Tuple .Take [N , n.type ], Tuple .Take [V , n.type ]],
74
+ NamedTuple [Tuple .Drop [N , n.type ], Tuple .Drop [V , n.type ]]) =
75
+ // would be nice if this could have type `Split[NamedTuple[N, V]]` instead, but
76
+ // we get a type error then. Similar for other methods here.
71
77
toTuple.splitAt(n)
72
78
73
79
/** The tuple consisting of all elements of this tuple followed by all elements
@@ -188,6 +194,12 @@ object NamedTuple:
188
194
*/
189
195
type From [T ] <: AnyNamedTuple
190
196
197
+ /** The type of the empty named tuple */
198
+ type Empty = EmptyTuple .type
199
+
200
+ /** The empty named tuple */
201
+ val Empty : Empty = EmptyTuple .asInstanceOf [Empty ]
202
+
191
203
end NamedTuple
192
204
193
205
/** Separate from NamedTuple object so that we can match on the opaque type NamedTuple. */
@@ -202,3 +214,4 @@ object NamedTupleDecomposition:
202
214
/** The value types of a named tuple represented as a regular tuple. */
203
215
type DropNames [NT <: AnyNamedTuple ] <: Tuple = NT match
204
216
case NamedTuple [_, x] => x
217
+
0 commit comments