@@ -141,6 +141,7 @@ object CodeGen {
141
141
142
142
private val initName = " $init$"
143
143
private val function1ImplClass = " scala.Function1$class"
144
+ private val function2ImplClass = " scala.Function2$class"
144
145
private val copyright =
145
146
"""
146
147
|/*
@@ -164,6 +165,9 @@ object CodeGen {
164
165
methods.map(indent).mkString(" \n\n " )
165
166
}
166
167
168
+ val function1SpecTs = List (Type .Int , Type .Long , Type .Float , Type .Double )
169
+ val function1SpecRs = List (Type .Void , Type .Boolean , Type .Int , Type .Float , Type .Long , Type .Double )
170
+
167
171
private def apply1MethodSpec (t1 : Type , r : Type ): String = {
168
172
val name = " apply$mc" + s " ${r.code}${t1.code}" + " $sp"
169
173
val applyCall = s " apply((T1) (( ${t1.ref}) v1)); "
@@ -177,12 +181,31 @@ object CodeGen {
177
181
}
178
182
179
183
private def apply1SpecMethods = {
180
- val ts = List (Type .Int , Type .Long , Type .Float , Type .Double )
181
- val rs = List (Type .Void , Type .Boolean , Type .Int , Type .Float , Type .Long , Type .Double )
182
- val methods = for (t1 <- ts; r <- rs) yield apply1MethodSpec(t1, r)
184
+ val methods = for (t1 <- function1SpecTs; r <- function1SpecRs) yield apply1MethodSpec(t1, r)
185
+ methods.map(indent).mkString(" \n\n " )
186
+ }
187
+
188
+ private def andThenComposeMethodSpec (t1 : Type , r : Type ): String = {
189
+ val suffix = " $mc" + s " ${r.code}${t1.code}" + " $sp"
190
+ s """
191
+ |default scala.Function1 compose $suffix(scala.Function1 g) {
192
+ | return compose(g);
193
+ |}
194
+ |default scala.Function1 andThen $suffix(scala.Function1 g) {
195
+ | return andThen(g);
196
+ |}
197
+ | """ .stripMargin.trim
198
+ }
199
+
200
+ // No longer needed under 2.11 (@unspecialized has been fixed), but harmless to keep around to avoid cross-publishing this artifact.
201
+ private def andThenComposeSpecMethods = {
202
+ val methods = for (t1 <- function1SpecTs; r <- function1SpecRs) yield andThenComposeMethodSpec(t1, r)
183
203
methods.map(indent).mkString(" \n\n " )
184
204
}
185
205
206
+ val function2SpecTs = List (Type .Int , Type .Long , Type .Double )
207
+ val function2SpecRs = function1SpecRs
208
+
186
209
private def apply2MethodSpec (t1 : Type , t2 : Type , r : Type ): String = {
187
210
val name = " apply$mc" + s " ${r.code}${t1.code}${t2.code}" + " $sp"
188
211
val applyCall = s " apply((T1) (( ${t1.ref}) v1), (T2) (( ${t2.ref}) v2)); "
@@ -196,22 +219,38 @@ object CodeGen {
196
219
}
197
220
198
221
private def apply2SpecMethods = {
199
- val ts = List (Type .Int , Type .Long , Type .Double )
200
- val rs = List (Type .Void , Type .Boolean , Type .Int , Type .Float , Type .Long , Type .Double )
201
- val methods = for (t1 <- ts; t2 <- ts; r <- rs) yield apply2MethodSpec(t1, t2, r)
222
+ val methods = for (t1 <- function2SpecTs; t2 <- function2SpecTs; r <- function2SpecRs) yield apply2MethodSpec(t1, t2, r)
223
+ methods.map(indent).mkString(" \n\n " )
224
+ }
225
+
226
+ private def curriedTupled2MethodSpec (t1 : Type , t2 : Type , r : Type ): String = {
227
+ val suffix = " $mc" + s " ${r.code}${t1.code}${t2.code}" + " $sp"
228
+ s """
229
+ |default scala.Function1 curried $suffix() {
230
+ | return curried();
231
+ |}
232
+ |default scala.Function1 tupled $suffix() {
233
+ | return tupled();
234
+ |}
235
+ | """ .stripMargin.trim
236
+ }
237
+
238
+ // No longer needed under 2.11 (@unspecialized has been fixed), but harmless to keep around to avoid cross-publishing this artifact.
239
+ private def curriedTupled2SpecMethods = {
240
+ val methods = for (t1 <- function2SpecTs; t2 <- function2SpecTs; r <- function2SpecRs) yield curriedTupled2MethodSpec(t1, t2, r)
202
241
methods.map(indent).mkString(" \n\n " )
203
242
}
204
243
205
244
def fN (n : Int ) = {
206
245
val header = arity(n).fHeader
207
- val applyMethods = n match {
246
+ val specializedVariants = n match {
208
247
case 0 => apply0SpecMethods
209
- case 1 => apply1SpecMethods
210
- case 2 => apply2SpecMethods
248
+ case 1 => apply1SpecMethods + " \n\n " + andThenComposeSpecMethods
249
+ case 2 => apply2SpecMethods + " \n\n " + curriedTupled2SpecMethods
211
250
case x => " "
212
251
}
213
252
val trailer = " }\n "
214
- List (header, applyMethods , trailer).mkString
253
+ List (header, specializedVariants , trailer).mkString
215
254
}
216
255
217
256
def pN (n : Int ) = arity(n).pN
0 commit comments