Skip to content

Commit ba4cee6

Browse files
authored
[data] remove Row (#1471)
1 parent de22374 commit ba4cee6

File tree

4 files changed

+6
-914
lines changed

4 files changed

+6
-914
lines changed

kyo-data/shared/src/main/scala/kyo/Record.scala

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@ import scala.language.implicitConversions
1818
* combinations with static type checking, making them ideal for configuration, data transformation, and API integrations where the shape
1919
* of data needs to be flexible but still type-safe.
2020
*
21-
* =Record vs Row=
22-
* Record and [[Row]] both provide type-safe named fields, but represent different abstractions:
23-
*
24-
* '''Record''' is a '''labeled set''' — fields are unordered, a record with more fields can be used where fewer are expected (structural
25-
* subtyping), and the same name can appear with different types. Use Record when different consumers need different field subsets or when
26-
* composing fields from multiple sources.
27-
*
28-
* '''Row''' is a '''labeled sequence''' — fields have a fixed order, each name is unique, and the type must match exactly. Use Row when
29-
* field order matters, when you need positional operations (head/tail/take/drop), or when working with case classes.
30-
*
31-
* The two interconvert freely:
32-
* {{{
33-
* val record = "name" ~ "Alice" & "age" ~ 30
34-
* val row = Row.fromRecord(record) // Record -> Row (rejects duplicate field names)
35-
* val back = row.toRecord // Row -> Record
36-
* }}}
37-
*
3821
* =Creation=
3922
* Records can be created through direct field construction using the `~` operator and combined with `&`:
4023
* {{{
@@ -183,6 +166,10 @@ object Record:
183166
case (n *: EmptyTuple, v *: EmptyTuple) => n ~ v
184167
case (n *: ns, v *: vs) => (n ~ v) & FieldsOf[ns, vs]
185168

169+
type FieldValues[T <: Tuple] <: Tuple = T match
170+
case EmptyTuple => EmptyTuple
171+
case Record.`~`[n, v] *: rest => v *: FieldValues[rest]
172+
186173
type ZipLookup[N <: String, T <: Tuple] = T match
187174
case (N ~ v) *: _ => v
188175
case _ *: rest => ZipLookup[N, rest]
@@ -196,11 +183,6 @@ object Record:
196183
*/
197184
def fromProduct[A](value: A)(using ar: AsRecord[A]): Record[ar.Fields] = ar.asRecord(value)
198185

199-
/** Creates a Record from a Row.
200-
*/
201-
inline def fromRow[A <: NamedTuple.AnyNamedTuple](row: Row[A]): Record[Row.ToRecordFields[Row.Names[A], Row.Values[A]]] =
202-
row.toRecord
203-
204186
/** A field in a Record, containing a name and associated type information.
205187
*
206188
* @param name
@@ -217,8 +199,8 @@ object Record:
217199
inline def fields(using ti: TypeIntersection[Fields]): List[String] =
218200
collectFieldNames[ti.AsTuple]
219201

220-
inline def values(using ti: TypeIntersection[Fields]): Row.FieldValues[ti.AsTuple] =
221-
collectValues[ti.AsTuple](self.toMap).asInstanceOf[Row.FieldValues[ti.AsTuple]]
202+
inline def values(using ti: TypeIntersection[Fields]): FieldValues[ti.AsTuple] =
203+
collectValues[ti.AsTuple](self.toMap).asInstanceOf[FieldValues[ti.AsTuple]]
222204

223205
def update[Name <: String & Singleton, Value](name: Name, value: Value)(using
224206
@implicitNotFound("""

kyo-data/shared/src/main/scala/kyo/Row.scala

Lines changed: 0 additions & 286 deletions
This file was deleted.

kyo-data/shared/src/test/scala/kyo/RecordTest.scala

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ class RecordTest extends Test:
105105
assert(record.value == 42)
106106
}
107107

108-
"fromRow" in {
109-
val row = Row((name = "Alice", age = 30))
110-
val record = Record.fromRow(row)
111-
typeCheck("""val _: Record["name" ~ String & "age" ~ Int] = record""")
112-
assert(record.name == "Alice")
113-
assert(record.age == 30)
114-
}
115108
}
116109

117110
"map" in {
@@ -1077,23 +1070,6 @@ class RecordTest extends Test:
10771070
}
10781071
}
10791072

1080-
"fromRow edge cases" - {
1081-
"single field" in {
1082-
val row = Row((name = "Alice"))
1083-
val record = Record.fromRow(row)
1084-
typeCheck("""val _: Record["name" ~ String] = record""")
1085-
assert(record.name == "Alice")
1086-
}
1087-
1088-
"three fields with complex types" in {
1089-
val row = Row((name = "Alice", scores = List(1, 2, 3), active = true))
1090-
val record = Record.fromRow(row)
1091-
assert(record.name == "Alice")
1092-
assert(record.scores == List(1, 2, 3))
1093-
assert(record.active == true)
1094-
}
1095-
}
1096-
10971073
"Render edge cases" - {
10981074
"render with duplicate field names" in {
10991075
val record = "x" ~ 1 & "x" ~ "hello"

0 commit comments

Comments
 (0)