@@ -121,20 +121,21 @@ object Record:
121
121
*/
122
122
val empty : Record [Any ] = Record [Any ](Map ())
123
123
124
- private def unsafeFrom [Fields : AsFields ](map : Map [Field [? , ? ], Any ]): Record [Fields ] = Record (map)
124
+ private def unsafeFrom [Fields ](map : Map [Field [? , ? ], Any ]): Record [Fields ] = Record (map)
125
125
126
126
inline def stage [Fields ]: StageOps [Fields ] = new StageOps [Fields ](())
127
127
128
128
class StageOps [Fields ](dummy : Unit ) extends AnyVal :
129
129
/** Applies `StageAs` logic to each field. Called on a record type `n1 ~ v1 & ... & nk ~ vk`, returns a new record of type
130
130
* `n1 ~ F[n1, v1] & ... & nk ~ F[nk, vk]`.
131
131
*/
132
- inline def apply [F [_, _]](as : StageAs [F ])(using
133
- asFields : AsFields [Fields ],
134
- ev : TypeIntersection [Fields ]
132
+ inline def apply [F [_, _]](as : Record .StageAs [F ])(using
133
+ initFields : AsFields [Fields ],
134
+ ev : TypeIntersection [Fields ],
135
+ targetFields : AsFields [ev.Map [~ .Map [F ]]]
135
136
): Record [ev.Map [~ .Map [F ]]] =
136
- unsafeFrom(TypeIntersection .inlineAll[Fields ](as).view.map {
137
- case (f, g) => (f.unwrap : Field [ ? , ? ] , g.unwrap)
137
+ Record . unsafeFrom(TypeIntersection .inlineAll[Fields ](as).view.map {
138
+ case (f, g) => (AsFieldAny .toField(f) , g.unwrap)
138
139
}.toMap)
139
140
end StageOps
140
141
@@ -255,27 +256,33 @@ object Record:
255
256
* @tparam A
256
257
* The field type, typically in the form of `"fieldName" ~ ValueType`
257
258
*/
258
- opaque type AsField [Name <: String , Value ] = Field [Name , Value ]
259
-
260
- private [kyo] type AsFieldAny [n, v] = AsField [n & String , v]
261
-
259
+ type AsField [Name <: String , Value ] = AsField .Type [Name , Value ]
262
260
object AsField :
261
+ opaque type Type [Name <: String , Value ] = Field [Name , Value ]
262
+
263
263
inline given [N <: String , V ](using tag : Tag [V ]): AsField [N , V ] =
264
264
Field (constValue[N ], tag)
265
265
266
- private [kyo] def toField [Name <: String , Value ](as : AsField [Name , Value ]): Field [? , ? ] = as
266
+ private [kyo] def fromField [Name <: String , Value ](field : Field [Name , Value ]): AsField [Name , Value ] = field
267
+ private [kyo] def toField [Name <: String , Value ](field : AsField [Name , Value ]): Field [Name , Value ] = field
267
268
end AsField
268
269
270
+ private [kyo] type AsFieldAny [n, v] = AsField [n & String , v]
271
+ private [kyo] object AsFieldAny :
272
+ def toField (as : ForSome2 [AsFieldAny ]): Field [? , ? ] = AsField .toField(as.unwrap)
273
+
269
274
/** Type class for working with sets of Record fields.
270
275
*
271
276
* AsFields provides type-safe field set operations and is used primarily for the `compact` operation on Records.
272
277
*
273
278
* @tparam A
274
279
* The combined type of all fields in the set
275
280
*/
276
- opaque type AsFields [+ A ] <: Set [ Field [ ? , ? ]] = Set [ Field [ ? , ? ] ]
281
+ type AsFields [+ A ] = AsFields . Type [ A ]
277
282
278
283
object AsFields :
284
+ opaque type Type [+ A ] <: Set [Field [? , ? ]] = Set [Field [? , ? ]]
285
+
279
286
def apply [A ](using af : AsFields [A ]): Set [Field [? , ? ]] = af
280
287
281
288
inline given [Fields ](using ev : TypeIntersection [Fields ]): AsFields [Fields ] =
@@ -317,10 +324,9 @@ object Record:
317
324
val nextTag = summonInline[Tag [F [n, v]]]
318
325
319
326
(
320
- ForSome2 .of[AsFieldAny ](Field (name, nextTag)),
327
+ ForSome2 .of[AsFieldAny ](AsField .fromField( Field (name, nextTag) )),
321
328
ForSome2 (stage[n, v](Field (name, prevTag)))
322
329
)
323
- end apply
324
330
end StageAs
325
331
end Record
326
332
@@ -334,7 +340,6 @@ object AsFieldsInternal:
334
340
end AsFieldInliner
335
341
336
342
inline def summonAsField [Fields ](using ev : TypeIntersection [Fields ]): Set [Field [? , ? ]] =
337
- TypeIntersection .inlineAll[Fields ](AsFieldInliner ).map { x =>
338
- Record .AsField .toField(x.unwrap)
339
- }.toSet
343
+ TypeIntersection .inlineAll[Fields ](AsFieldInliner ).map(Record .AsFieldAny .toField).toSet
344
+ end summonAsField
340
345
end AsFieldsInternal
0 commit comments