Skip to content

Commit 7e022f2

Browse files
sjrdchuwy
authored andcommitted
chore: prepare for the restrictions on match types in SIP-56 (close #12)
Nested "type test extractors" like `IsSingleton` are not allowed in the match types of SIP-56. Some of them were redundant and were removed. The others were turned in explicit inner match types.
1 parent af2041c commit 7e022f2

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

core/src/main/scala/skunk/tables/internal/typeops.scala

+17-18
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,17 @@ inline def findT[C <: Tuple, Label <: Singleton]: Find[C, Label] =
8585
/** Pick only `TypedColumns` with certain labels */
8686
type Pick[Columns <: Tuple, Labels <: Tuple] <: Tuple =
8787
Labels match
88-
case EmptyTuple => EmptyTuple
89-
case IsSingleton[h] *: t => Find[Columns, h] *: Pick[Columns, t]
90-
91-
inline def pickT[C <: Tuple, Labels <: Tuple]: Pick[C, Labels] =
92-
inline erasedValue[Labels] match
93-
case _: EmptyTuple => EmptyTuple
94-
case _: (IsSingleton[h] *: t) => findT[C, h] *: pickT[C, t]
88+
case EmptyTuple =>
89+
EmptyTuple
90+
case h *: t =>
91+
h match
92+
case Singleton => Find[Columns, h & Singleton] *: Pick[Columns, t]
9593

9694
type Reify[C <: Tuple] <: Tuple =
9795
C match
9896
case EmptyTuple =>
9997
EmptyTuple
100-
case TypedColumn[IsSingleton[n], a, t, c] *: tail =>
98+
case TypedColumn[n, a, t, c] *: tail =>
10199
TypedColumn[n, a, t, c] *: Reify[tail]
102100

103101
// WARNING: it doesn't work if there's a type with given instance not
@@ -107,22 +105,22 @@ inline def reifyT[C <: Tuple]: Reify[C] =
107105
inline erasedValue[C] match
108106
case _: EmptyTuple =>
109107
EmptyTuple
110-
case _: (TypedColumn[IsSingleton[n], a, t, c] *: tail) =>
108+
case _: (TypedColumn[n, a, t, c] *: tail) =>
111109
TypedColumn[n, a, t, c](constValue[n], summonInline[IsColumn[a]]) *: reifyT[tail]
112110

113111
type ReifyN[C <: NonEmptyTuple] <: NonEmptyTuple =
114112
C match
115-
case TypedColumn[IsSingleton[n], a, t, c] *: EmptyTuple =>
113+
case TypedColumn[n, a, t, c] *: EmptyTuple =>
116114
TypedColumn[n, a, t, c] *: EmptyTuple
117-
case TypedColumn[IsSingleton[n], a, t, c] *: h2 *: tail =>
115+
case TypedColumn[n, a, t, c] *: h2 *: tail =>
118116
TypedColumn[n, a, t, c] *: ReifyN[h2 *: tail]
119117

120118
/** Reify a homogenous tuple of `TypedColumn` */
121119
inline def reifyNT[C <: NonEmptyTuple]: ReifyN[C] =
122120
inline erasedValue[C] match
123-
case _: (TypedColumn[IsSingleton[n], a, t, c] *: EmptyTuple) =>
121+
case _: (TypedColumn[n, a, t, c] *: EmptyTuple) =>
124122
TypedColumn[n, a, t, c](constValue[n], summonInline[IsColumn[a]]) *: EmptyTuple
125-
case _: (TypedColumn[IsSingleton[n], a, t, c] *: h2 *: tail) =>
123+
case _: (TypedColumn[n, a, t, c] *: h2 *: tail) =>
126124
TypedColumn[n, a, t, c](constValue[n], summonInline[IsColumn[a]]) *: reifyNT[h2 *: tail]
127125

128126
type GetNames[C <: Tuple] <: Tuple =
@@ -141,8 +139,12 @@ inline def getNamesT[C <: Tuple]: GetNames[C] =
141139

142140
type GetInNames[I <: NonEmptyTuple] <: NonEmptyTuple =
143141
I match
144-
case TypedColumn.In[IsSingleton[n], ?, ?] *: EmptyTuple => n *: EmptyTuple
145-
case TypedColumn.In[IsSingleton[n], ?, ?] *: t => n *: GetInNames[t]
142+
case TypedColumn.In[n, ?, ?] *: EmptyTuple =>
143+
n match
144+
case Singleton => n *: EmptyTuple
145+
case TypedColumn.In[n, ?, ?] *: t =>
146+
n match
147+
case Singleton => n *: GetInNames[t]
146148

147149
/** Match type to transform `(a, b, c, d)` of `TypedColumn.In` into `(((a, b), c), d)` (or `a ~ b ~
148150
* c ~ d`)
@@ -159,9 +161,6 @@ type TwiddleInGo[I <: Tuple, A <: Tuple] =
159161

160162
// Generic operations
161163

162-
/** Type-level unapply, checking if `T` is a singleton */
163-
type IsSingleton[T <: Singleton] = T
164-
165164
/** If `A` in tuple `T` - return `True` branch, otherwise `False` branch */
166165
type IfIn[T <: Tuple, A, True, False] <: True | False = T match
167166
case EmptyTuple => False

0 commit comments

Comments
 (0)