@@ -25,6 +25,7 @@ object NamedTuple:
25
25
extension [V <: Tuple ](x : V )
26
26
inline def withNames [N <: Tuple ]: NamedTuple [N , V ] = x
27
27
28
+ import NamedTupleDecomposition .{Names , DropNames }
28
29
export NamedTupleDecomposition .{
29
30
Names , DropNames ,
30
31
apply , size , init , head , last , tail , take , drop , splitAt , ++ , map , reverse , zip , toList , toArray , toIArray
@@ -134,65 +135,57 @@ object NamedTupleDecomposition:
134
135
import NamedTuple .*
135
136
extension [N <: Tuple , V <: Tuple ](x : NamedTuple [N , V ])
136
137
/** The value (without the name) at index `n` of this tuple */
137
- inline def apply (n : Int ): Tuple . Elem [V , n.type ] =
138
+ inline def apply (n : Int ): Elem [NamedTuple [ N , V ] , n.type ] =
138
139
inline x.toTuple match
139
- case tup : NonEmptyTuple => tup(n).asInstanceOf [Tuple . Elem [V , n.type ]]
140
- case tup => tup.productElement(n).asInstanceOf [Tuple . Elem [V , n.type ]]
140
+ case tup : NonEmptyTuple => tup(n).asInstanceOf [Elem [NamedTuple [ N , V ] , n.type ]]
141
+ case tup => tup.productElement(n).asInstanceOf [Elem [NamedTuple [ N , V ] , n.type ]]
141
142
142
143
/** The number of elements in this tuple */
143
- inline def size : Tuple . Size [V ] = x.toTuple.size
144
+ inline def size : Size [NamedTuple [ N , V ] ] = x.toTuple.size
144
145
145
146
/** The first element value of this tuple */
146
- inline def head : Tuple . Elem [ V , 0 ] = apply(0 )
147
+ inline def head : Head [ NamedTuple [ N , V ] ] = apply(0 )
147
148
148
149
/** The last element value of this tuple */
149
- inline def last : Tuple . Last [V ] = apply(size - 1 ).asInstanceOf [Tuple .Last [V ]]
150
+ inline def last : Last [NamedTuple [ N , V ] ] = apply(size - 1 ).asInstanceOf [Tuple .Last [V ]]
150
151
151
152
/** The tuple consisting of all elements of this tuple except the last one */
152
- inline def init : NamedTuple [ Tuple . Init [N ], Tuple . Init [ V ]] =
153
- x.toTuple.take(size - 1 ).asInstanceOf [NamedTuple [ Tuple . Init [N ], Tuple . Init [ V ]]]
153
+ inline def init : Init [NamedTuple [ N , V ]] =
154
+ x.toTuple.take(size - 1 ).asInstanceOf [Init [NamedTuple [ N , V ]]]
154
155
155
156
/** The tuple consisting of all elements of this tuple except the first one */
156
- inline def tail : NamedTuple [ Tuple . Tail [N ], Tuple . Tail [ V ]] =
157
- x.toTuple.drop(1 ).asInstanceOf [NamedTuple [ Tuple . Tail [N ], Tuple . Tail [ V ]]]
157
+ inline def tail : Tail [NamedTuple [ N , V ]] =
158
+ x.toTuple.drop(1 ).asInstanceOf [Tail [NamedTuple [ N , V ]]]
158
159
159
160
/** The tuple consisting of the first `n` elements of this tuple, or all
160
161
* elements if `n` exceeds `size`.
161
162
*/
162
- inline def take (n : Int ): NamedTuple [Tuple .Take [N , n.type ], Tuple .Take [V , n.type ]] =
163
- x.toTuple.take(n)
163
+ inline def take (n : Int ): Take [NamedTuple [N , V ], n.type ] = x.toTuple.take(n)
164
164
165
165
/** The tuple consisting of all elements of this tuple except the first `n` ones,
166
166
* or no elements if `n` exceeds `size`.
167
167
*/
168
- inline def drop (n : Int ): NamedTuple [Tuple .Drop [N , n.type ], Tuple .Drop [V , n.type ]] =
169
- x.toTuple.drop(n)
168
+ inline def drop (n : Int ): Drop [NamedTuple [N , V ], n.type ] = x.toTuple.drop(n)
170
169
171
170
/** The tuple `(x.take(n), x.drop(n))` */
172
- inline def splitAt (n : Int ):
173
- (NamedTuple [Tuple .Take [N , n.type ], Tuple .Take [V , n.type ]],
174
- NamedTuple [Tuple .Drop [N , n.type ], Tuple .Drop [V , n.type ]]) =
175
- // would be nice if this could have type `Split[NamedTuple[N, V]]` instead, but
176
- // we get a type error then. Similar for other methods here.
177
- x.toTuple.splitAt(n)
171
+ inline def splitAt (n : Int ): Split [NamedTuple [N , V ], n.type ] = x.toTuple.splitAt(n)
178
172
179
173
/** The tuple consisting of all elements of this tuple followed by all elements
180
174
* of tuple `that`. The names of the two tuples must be disjoint.
181
175
*/
182
176
inline def ++ [N2 <: Tuple , V2 <: Tuple ](that : NamedTuple [N2 , V2 ])(using Tuple .Disjoint [N , N2 ] =:= true )
183
- : NamedTuple [ Tuple . Concat [N , N2 ], Tuple . Concat [ V , V2 ]]
177
+ : Concat [NamedTuple [ N , V ], NamedTuple [ N2 , V2 ]]
184
178
= x.toTuple ++ that.toTuple
185
179
186
180
/** The named tuple consisting of all element values of this tuple mapped by
187
181
* the polymorphic mapping function `f`. The names of elements are preserved.
188
182
* If `x = (n1 = v1, ..., ni = vi)` then `x.map(f) = `(n1 = f(v1), ..., ni = f(vi))`.
189
183
*/
190
- inline def map [F [_]](f : [t] => t => F [t]): NamedTuple [N , Tuple . Map [ V , F ] ] =
184
+ inline def map [F [_]](f : [t] => t => F [t]): Map [ NamedTuple [N , V ] , F ] =
191
185
x.toTuple.map(f).asInstanceOf [NamedTuple [N , Tuple .Map [V , F ]]]
192
186
193
187
/** The named tuple consisting of all elements of this tuple in reverse */
194
- inline def reverse : NamedTuple [Tuple .Reverse [N ], Tuple .Reverse [V ]] =
195
- x.toTuple.reverse
188
+ inline def reverse : Reverse [NamedTuple [N , V ]] = x.toTuple.reverse
196
189
197
190
/** The named tuple consisting of all elements values of this tuple zipped
198
191
* with corresponding element values in named tuple `that`.
@@ -201,7 +194,7 @@ object NamedTupleDecomposition:
201
194
* The names of `x` and `that` at the same index must be the same.
202
195
* The result tuple keeps the same names as the operand tuples.
203
196
*/
204
- inline def zip [V2 <: Tuple ](that : NamedTuple [N , V2 ]): NamedTuple [N , Tuple . Zip [ V , V2 ]] =
197
+ inline def zip [V2 <: Tuple ](that : NamedTuple [N , V2 ]): Zip [ NamedTuple [N , V ], NamedTuple [ N , V2 ]] =
205
198
x.toTuple.zip(that.toTuple)
206
199
207
200
/** A list consisting of all element values */
0 commit comments