Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac5e5d0

Browse files
committed
Add method applyToContext to all FunctionN traits
1 parent ff1b1dd commit ac5e5d0

27 files changed

+147
-4
lines changed

project/MimaFilters.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ object MimaFilters extends AutoPlugin {
3939
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.concurrent.impl.FutureConvertersImpl#P.accept"),
4040
ProblemFilters.exclude[IncompatibleMethTypeProblem]("scala.concurrent.impl.FutureConvertersImpl#P.andThen"),
4141

42+
ProblemFilters.exclude[DirectMissingMethodProblem]("*.applyToContext"),
4243
)
4344

4445
override val buildSettings = Seq(

project/genprod.scala

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ raw"""
110110
* }
111111
* assert(greeting() == anonfun0())
112112
* """)
113-
override def moreMethods = ""
113+
override def moreMethods = """ /** Apply the body of this function to the argument which is taken from the implicit context.
114+
* @return the result of function application.
115+
*/
116+
@annotation.unspecialized def applyToContext: R = apply()
117+
"""
114118
}
115119

116120
object FunctionOne extends Function(1) {
@@ -131,6 +135,11 @@ object FunctionOne extends Function(1) {
131135
* is that the latter can specify inputs which it will not handle."""
132136

133137
override def moreMethods = """
138+
/** Apply the body of this function to the argument which is taken from the implicit context.
139+
* @return the result of function application.
140+
*/
141+
@annotation.unspecialized def applyToContext(implicit v1: T1): R = apply(v1)
142+
134143
/** Composes two instances of Function1 in a new Function1, with this function applied last.
135144
*
136145
* @tparam A the type to which function `g` can be applied
@@ -237,6 +246,16 @@ class Function(val i: Int) extends Group("Function") with Arity {
237246

238247
private def commaXs = xdefs.mkString("(", ", ", ")")
239248

249+
def applyToContextMethod = {
250+
def comment =
251+
""" /** Apply the body of this function to the arguments which are taken from the implicit context.
252+
* @return the result of function application.
253+
*/
254+
"""
255+
comment + " @annotation.unspecialized def applyToContext(implicit %s): R = apply%s\n".format(
256+
funArgs, vdefs.mkString("(", ", ", ")"))
257+
}
258+
240259
// (x1: T1) => (x2: T2) => (x3: T3) => (x4: T4) => apply(x1,x2,x3,x4)
241260
def shortCurry = {
242261
val body = "apply" + commaXs
@@ -281,7 +300,7 @@ class Function(val i: Int) extends Group("Function") with Arity {
281300
)
282301
}
283302

284-
override def moreMethods = curryMethod + tupleMethod
303+
override def moreMethods = applyToContextMethod ++ curryMethod + tupleMethod
285304
} // object Function
286305

287306

src/library/scala/Function.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,34 @@ object Function {
127127
def untupled[T1, T2, T3, T4, T5, R](f: ((T1, T2, T3, T4, T5)) => R): (T1, T2, T3, T4, T5) => R = {
128128
(x1, x2, x3, x4, x5) => f((x1, x2, x3, x4, x5))
129129
}
130+
131+
/** Apply the body of this function to the arguments which are taken from the implicit context.
132+
*/
133+
def applyToContext[R](f: () => R): R =
134+
f()
135+
136+
/** Apply the body of this function to the arguments which are taken from the implicit context.
137+
*/
138+
def applyToContext[T1, R](f: T1 => R)(implicit x1: T1): R =
139+
f(x1)
140+
141+
/** Apply the body of this function to the arguments which are taken from the implicit context.
142+
*/
143+
def applyToContext[T1, T2, R](f: (T1, T2) => R)(implicit x1: T1, x2: T2): R =
144+
f(x1, x2)
145+
146+
/** Apply the body of this function to the arguments which are taken from the implicit context.
147+
*/
148+
def applyToContext[T1, T2, T3, R](f: (T1, T2, T3) => R)(implicit x1: T1, x2: T2, x3: T3): R =
149+
f(x1, x2, x3)
150+
151+
/** Apply the body of this function to the arguments which are taken from the implicit context.
152+
*/
153+
def applyToContext[T1, T2, T3, T4, R](f: (T1, T2, T3, T4) => R)(implicit x1: T1, x2: T2, x3: T3, x4: T4): R =
154+
f(x1, x2, x3, x4)
155+
156+
/** Apply the body of this function to the arguments which are taken from the implicit context.
157+
*/
158+
def applyToContext[T1, T2, T3, T4, T5, R](f: (T1, T2, T3, T4, T5) => R)(implicit x1: T1, x2: T2, x3: T3, x4: T4, x5: T5): R =
159+
f(x1, x2, x3, x4, x5)
130160
}

src/library/scala/Function0.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// GENERATED CODE: DO NOT EDIT.
14-
// genprod generated these sources at: 2022-01-17T20:47:12.170348200Z
14+
// genprod generated these sources at: 2024-11-11T11:11:11.910758899Z
1515

1616
package scala
1717

@@ -40,6 +40,10 @@ trait Function0[@specialized(Specializable.Primitives) +R] extends AnyRef { self
4040
* @return the result of function application.
4141
*/
4242
def apply(): R
43+
/** Apply the body of this function to the argument which is taken from the implicit context.
44+
* @return the result of function application.
45+
*/
46+
@annotation.unspecialized def applyToContext: R = apply()
4347

4448
override def toString(): String = "<function0>"
4549
}

src/library/scala/Function1.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ trait Function1[@specialized(Specializable.Arg) -T1, @specialized(Specializable.
7070
*/
7171
def apply(v1: T1): R
7272

73+
/** Apply the body of this function to the argument which is taken from the implicit context.
74+
* @return the result of function application.
75+
*/
76+
@annotation.unspecialized def applyToContext(implicit v1: T1): R = apply(v1)
77+
7378
/** Composes two instances of `Function1` in a new `Function1`, with this function applied last.
7479
*
7580
* @tparam A the type to which function `g` can be applied

src/library/scala/Function10.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ trait Function10[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, +R] extends
2323
* @return the result of function application.
2424
*/
2525
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10): R
26+
/** Apply the body of this function to the arguments which are taken from the implicit context.
27+
* @return the result of function application.
28+
*/
29+
@annotation.unspecialized def applyToContext(implicit v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10): R = apply(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2630
/** Creates a curried version of this function.
2731
*
2832
* @return a function `f` such that `f(x1)(x2)(x3)(x4)(x5)(x6)(x7)(x8)(x9)(x10) == apply(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)`

src/library/scala/Function11.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ trait Function11[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, +R] ex
2323
* @return the result of function application.
2424
*/
2525
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11): R
26+
/** Apply the body of this function to the arguments which are taken from the implicit context.
27+
* @return the result of function application.
28+
*/
29+
@annotation.unspecialized def applyToContext(implicit v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11): R = apply(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2630
/** Creates a curried version of this function.
2731
*
2832
* @return a function `f` such that `f(x1)(x2)(x3)(x4)(x5)(x6)(x7)(x8)(x9)(x10)(x11) == apply(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)`

src/library/scala/Function12.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ trait Function12[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12,
2323
* @return the result of function application.
2424
*/
2525
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12): R
26+
/** Apply the body of this function to the arguments which are taken from the implicit context.
27+
* @return the result of function application.
28+
*/
29+
@annotation.unspecialized def applyToContext(implicit v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12): R = apply(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2630
/** Creates a curried version of this function.
2731
*
2832
* @return a function `f` such that `f(x1)(x2)(x3)(x4)(x5)(x6)(x7)(x8)(x9)(x10)(x11)(x12) == apply(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)`

src/library/scala/Function13.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ trait Function13[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12,
2323
* @return the result of function application.
2424
*/
2525
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12, v13: T13): R
26+
/** Apply the body of this function to the arguments which are taken from the implicit context.
27+
* @return the result of function application.
28+
*/
29+
@annotation.unspecialized def applyToContext(implicit v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12, v13: T13): R = apply(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2630
/** Creates a curried version of this function.
2731
*
2832
* @return a function `f` such that `f(x1)(x2)(x3)(x4)(x5)(x6)(x7)(x8)(x9)(x10)(x11)(x12)(x13) == apply(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13)`

src/library/scala/Function14.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ trait Function14[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12,
2323
* @return the result of function application.
2424
*/
2525
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12, v13: T13, v14: T14): R
26+
/** Apply the body of this function to the arguments which are taken from the implicit context.
27+
* @return the result of function application.
28+
*/
29+
@annotation.unspecialized def applyToContext(implicit v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12, v13: T13, v14: T14): R = apply(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2630
/** Creates a curried version of this function.
2731
*
2832
* @return a function `f` such that `f(x1)(x2)(x3)(x4)(x5)(x6)(x7)(x8)(x9)(x10)(x11)(x12)(x13)(x14) == apply(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14)`

0 commit comments

Comments
 (0)