Skip to content

Commit 339eb4b

Browse files
committed
remove some wrapper classes
1 parent 9efa287 commit 339eb4b

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

scalasql/namedtuples/src/SimpleTableMacros.scala

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ object SimpleTableMacros {
2727
)[U: ClassTag](f: (T, Int) => IterableOnce[U]): IArray[U] = {
2828
IArray.from(t.productIterator.asInstanceOf[Iterator[T]].zipWithIndex.flatMap(f.tupled))
2929
}
30-
def asIArrayUnwrap[T](t: Tuple)[U: ClassTag](f: T => U): IArray[U] = {
31-
IArray.from(t.productIterator.asInstanceOf[Iterator[T]].map(f))
32-
}
3330
def unwrapLabels(t: Tuple, labels: IArray[String]): IndexedSeq[String] = {
34-
asIArrayFlatUnwrapWithIndex[BaseLabels[?, ?]](t)((l, i) => l.fetch(labels(i))).toIndexedSeq
31+
asIArrayFlatUnwrapWithIndex[BaseLabels[Any, Any]](t)((l, i) => l(labels(i))).toIndexedSeq
3532
}
3633
def unwrapColumns(t: Tuple): IArray[AnyRef] = {
37-
asIArrayUnwrap[BaseColumn[?, ?]](t)(_.value)
34+
asIArray[BaseColumn[Any, Any]](t)
3835
}
3936
def make[C](m: Mirror.ProductOf[C], data: IArray[AnyRef]): C = {
4037
class ArrayProduct extends Product {
@@ -51,10 +48,10 @@ object SimpleTableMacros {
5148
mappers: DialectTypeMappers,
5249
tableRef: TableRef
5350
): IArray[AnyRef] = {
54-
val cols = mappers match
55-
case given DialectTypeMappers =>
56-
tableRef match
57-
case given TableRef => compiletime.summonAll[Columns]
51+
val cols = tableRef match
52+
case given TableRef =>
53+
import mappers.given
54+
compiletime.summonAll[Columns]
5855
unwrapColumns(cols)
5956
}
6057

@@ -87,32 +84,32 @@ object SimpleTableMacros {
8784
): BaseRowExpr[T] = delegate
8885
}
8986

90-
class BaseColumn[L, T](val value: AnyRef)
87+
opaque type BaseColumn[L, T] = AnyRef
9188
trait BaseColumnLowPrio {
92-
inline given notFound: [L <: String, T]
93-
=> (l: ValueOf[L], mappers: DialectTypeMappers, ref: TableRef) => BaseColumn[L, T] =
94-
import mappers.{*, given}
89+
given notFound: [L <: String, T]
90+
=> (l: ValueOf[L], ref: TableRef, mapper: TypeMapper[T])
91+
=> BaseColumn[L, T] =
9592
val col = new Column[T](
9693
ref,
9794
Table.columnNameOverride(ref.value)(l.value)
98-
)(using compiletime.summonInline[TypeMapper[T]])
99-
BaseColumn(col)
95+
)
96+
col
10097
}
10198
object BaseColumn extends BaseColumnLowPrio {
10299
given foundMeta: [L <: String, T]
103100
=> (mappers: DialectTypeMappers, ref: TableRef, m: SimpleTable.WrappedMetadata[T])
104101
=> BaseColumn[L, T] =
105-
BaseColumn(m.metadata.metadata0.vExpr(ref, mappers).asInstanceOf[AnyRef])
102+
m.metadata.metadata0.vExpr(ref, mappers).asInstanceOf[AnyRef]
106103
}
107104

108-
class BaseLabels[L, C](val fetch: String => Seq[String])
105+
opaque type BaseLabels[L, C] = String => Seq[String]
109106
trait BaseLabelsLowPrio {
110107
given notFound: [L <: String, C] => BaseLabels[L, C] =
111-
new BaseLabels(fetch = label => Seq(label))
108+
label => Seq(label)
112109
}
113110
object BaseLabels extends BaseLabelsLowPrio {
114111
given foundMeta: [L, C] => (m: SimpleTable.WrappedMetadata[C]) => BaseLabels[L, C] =
115-
new BaseLabels(fetch = _ => m.metadata.metadata0.walkLabels0())
112+
_ => m.metadata.metadata0.walkLabels0()
116113
}
117114

118115
def setNonNull[T](r: AtomicReference[T | Null])(f: => T): T = {

0 commit comments

Comments
 (0)