-
Notifications
You must be signed in to change notification settings - Fork 9
/
BuilderConfig.scala
161 lines (132 loc) 路 8.21 KB
/
BuilderConfig.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package io.github.arainko.ducktape
import io.github.arainko.ducktape.internal.NotQuotedException
import scala.annotation.{ compileTimeOnly, implicitNotFound }
import scala.deriving.Mirror
import scala.util.NotGiven
opaque type BuilderConfig[Source, Dest] = Unit
opaque type FallibleBuilderConfig[F[+x], Source, Dest] = Unit
object Field {
@compileTimeOnly("'Field.const' needs to be erased from the AST with a macro.")
def const[Source, Dest, FieldType, ActualType](selector: Dest => FieldType, value: ActualType)(using
ev1: ActualType <:< FieldType,
@implicitNotFound("Field.const is supported for product types only, but ${Source} is not a product type.")
ev2: Mirror.ProductOf[Source],
@implicitNotFound("Field.const is supported for product types only, but ${Dest} is not a product type.")
ev3: Mirror.ProductOf[Dest]
): BuilderConfig[Source, Dest] = throw NotQuotedException("Field.const")
@compileTimeOnly("'Field.computed' needs to be erased from the AST with a macro.")
def computed[Source, Dest, FieldType, ActualType](selector: Dest => FieldType, f: Source => ActualType)(using
ev1: ActualType <:< FieldType,
@implicitNotFound("Field.computed is supported for product types only, but ${Source} is not a product type.")
ev2: Mirror.ProductOf[Source],
@implicitNotFound("Field.computed is supported for product types only, but ${Dest} is not a product type.")
ev3: Mirror.ProductOf[Dest]
): BuilderConfig[Source, Dest] = throw NotQuotedException("Field.computed")
@compileTimeOnly("'Field.renamed' needs to be erased from the AST with a macro.")
def renamed[Source, Dest, SourceFieldType, DestFieldType](
destSelector: Dest => DestFieldType,
sourceSelector: Source => SourceFieldType
)(using
ev1: SourceFieldType <:< DestFieldType,
@implicitNotFound("Field.renamed is supported for product types only, but ${Source} is not a product type.")
ev2: Mirror.ProductOf[Source],
@implicitNotFound("Field.renamed is supported for product types only, but ${Dest} is not a product type.")
ev3: Mirror.ProductOf[Dest]
): BuilderConfig[Source, Dest] = throw NotQuotedException("Field.renamed")
@compileTimeOnly("'Field.default' needs to be erased from the AST with a macro.")
def default[Source, Dest, FieldType](selector: Dest => FieldType)(using
@implicitNotFound("Field.default is supported for product types only, but ${Source} is not a product type.")
ev1: Mirror.ProductOf[Source],
@implicitNotFound("Field.default is supported for product types only, but ${Dest} is not a product type.")
ev2: Mirror.ProductOf[Dest]
): BuilderConfig[Source, Dest] = throw new NotQuotedException("Field.default")
@compileTimeOnly("'Field.allMatching' needs to be erased from the AST with a macro.")
def allMatching[Source, Dest, FieldSource](
fieldSource: FieldSource
)(using
@implicitNotFound("Field.allMatching is supported for product types only, but ${Source} is not a product type.")
ev1: Mirror.ProductOf[Source],
@implicitNotFound("Field.allMatching is supported for product types only, but ${Dest} is not a product type.")
ev2: Mirror.ProductOf[Dest],
@implicitNotFound("Field.allMatching is supported for product types only, but ${FieldSource} is not a product type.")
ev3: Mirror.ProductOf[FieldSource]
): BuilderConfig[Source, Dest] = throw NotQuotedException("Field.allMatching")
@compileTimeOnly("'Field.fallibleConst' needs to be erased from the AST with a macro.")
def fallibleConst[F[+x], Source, Dest, FieldType, ActualType](selector: Dest => FieldType, value: F[ActualType])(using
ev1: ActualType <:< FieldType,
@implicitNotFound("Field.fallibleConst is supported for product types only, but ${Source} is not a product type.")
ev2: Mirror.ProductOf[Source],
@implicitNotFound("Field.fallibleConst is supported for product types only, but ${Dest} is not a product type.")
ev3: Mirror.ProductOf[Dest]
): FallibleBuilderConfig[F, Source, Dest] = throw NotQuotedException("Field.fallibleConst")
@compileTimeOnly("'Field.fallibleComputed' needs to be erased from the AST with a macro.")
def fallibleComputed[F[+x], Source, Dest, FieldType, ActualType](selector: Dest => FieldType, f: Source => F[ActualType])(using
ev1: ActualType <:< FieldType,
@implicitNotFound("Field.fallibleComputed is supported for product types only, but ${Source} is not a product type.")
ev2: Mirror.ProductOf[Source],
@implicitNotFound("Field.fallibleComputed is supported for product types only, but ${Dest} is not a product type.")
ev3: Mirror.ProductOf[Dest]
): FallibleBuilderConfig[F, Source, Dest] = throw NotQuotedException("Field.fallibleComputed")
}
object Case {
@compileTimeOnly("'Case.const' needs to be erased from the AST with a macro.")
def const[SourceSubtype]: Case.Const[SourceSubtype] = throw NotQuotedException("Case.const")
opaque type Const[SourceSubtype] = Unit
object Const {
extension [SourceSubtype](inst: Const[SourceSubtype]) {
@compileTimeOnly("'Case.const' needs to be erased from the AST with a macro.")
def apply[Source, Dest](const: Dest)(using
@implicitNotFound("Case.computed is only supported for coproducts but ${Source} is not a coproduct.")
ev1: Mirror.SumOf[Source],
ev2: SourceSubtype <:< Source,
@implicitNotFound("Case.const is only supported for subtypes of ${Source}.")
ev3: NotGiven[SourceSubtype =:= Source]
): BuilderConfig[Source, Dest] = throw NotQuotedException("Case.const")
}
}
@compileTimeOnly("'Case.computed' needs to be erased from the AST with a macro.")
def computed[SourceSubtype]: Case.Computed[SourceSubtype] = throw NotQuotedException("Case.computed")
opaque type Computed[SourceSubtype] = Unit
object Computed {
extension [SourceSubtype](inst: Computed[SourceSubtype]) {
@compileTimeOnly("'Case.computed' needs to be erased from the AST with a macro.")
def apply[Source, Dest](f: SourceSubtype => Dest)(using
@implicitNotFound("Case.computed is only supported for coproducts but ${Source} is not a coproduct.")
ev1: Mirror.SumOf[Source],
ev2: SourceSubtype <:< Source,
@implicitNotFound("Case.computed is only supported for subtypes of ${Source}.")
ev3: NotGiven[SourceSubtype =:= Source]
): BuilderConfig[Source, Dest] = throw NotQuotedException("Case.computed")
}
}
@compileTimeOnly("'Case.fallibleConst' needs to be erased from the AST with a macro.")
def fallibleConst[SourceSubtype]: Case.FallibleConst[SourceSubtype] = throw NotQuotedException("Case.fallibleComputed")
opaque type FallibleConst[SourceSubtype] = Unit
object FallibleConst {
extension [SourceSubtype](inst: FallibleConst[SourceSubtype]) {
@compileTimeOnly("'Case.fallibleConst' needs to be erased from the AST with a macro.")
def apply[F[+x], Source, Dest](const: F[Dest])(using
@implicitNotFound("Case.fallibleConst is only supported for coproducts but ${Source} is not a coproduct.")
ev1: Mirror.SumOf[Source],
ev2: SourceSubtype <:< Source,
@implicitNotFound("Case.fallibleConst is only supported for subtypes of ${Source}.")
ev3: NotGiven[SourceSubtype =:= Source]
): FallibleBuilderConfig[F, Source, Dest] = throw NotQuotedException("Case.computed")
}
}
@compileTimeOnly("'Case.fallibleConst' needs to be erased from the AST with a macro.")
def fallibleComputed[SourceSubtype]: Case.FallibleComputed[SourceSubtype] = throw NotQuotedException("Case.fallibleComputed")
opaque type FallibleComputed[SourceSubtype] = Unit
object FallibleComputed {
extension [SourceSubtype](inst: FallibleComputed[SourceSubtype]) {
@compileTimeOnly("'Case.fallibleComputed' needs to be erased from the AST with a macro.")
def apply[F[+x], Source, Dest](const: SourceSubtype => F[Dest])(using
@implicitNotFound("Case.fallibleComputed is only supported for coproducts but ${Source} is not a coproduct.")
ev1: Mirror.SumOf[Source],
ev2: SourceSubtype <:< Source,
@implicitNotFound("Case.fallibleComputed is only supported for subtypes of ${Source}.")
ev3: NotGiven[SourceSubtype =:= Source]
): FallibleBuilderConfig[F, Source, Dest] = throw NotQuotedException("Case.computed")
}
}
}