Skip to content

Commit a579756

Browse files
committed
Rename TupledFunction.apply to TupledFunction.tuple
1 parent 3c2005d commit a579756

7 files changed

+39
-39
lines changed

docs/docs/reference/other-new-features/tupled-function.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The type class `TupleFunction` provides a way to abstract directly over function
1818
*/
1919
@implicitNotFound("${F} cannot be tupled as ${G}")
2020
sealed trait TupledFunction[F, G] {
21-
def apply(f: F): G
21+
def tuple(f: F): G
2222
}
2323
```
2424

@@ -41,7 +41,7 @@ Examples
4141
* @tparam Args the tuple type with the same types as the function arguments of F
4242
* @tparam R the return type of F
4343
*/
44-
def (f: F) tupled[F, Args <: Tuple, R] given (tupled: TupledFunction[F, Args => R]): Args => R = tupled(f)
44+
def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): Args => R = tf.tuple(f)
4545
```
4646

4747
`TupledFunction` can also be used to generalize the [`Tuple1.compose`](https://github.com/lampepfl/dotty/tests/run/tupled-function-compose.scala) and [`Tuple1.andThen`](https://github.com/lampepfl/dotty/tests/run/tupled-function-andThen.scala) methods to compose functions of larger arities and with functions that return tuples.
@@ -55,7 +55,7 @@ def (f: F) tupled[F, Args <: Tuple, R] given (tupled: TupledFunction[F, Args =>
5555
* @tparam GArgs the tuple type with the same types as the function arguments of G
5656
* @tparam R the return type of F
5757
*/
58-
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tupledG: TupledFunction[G, GArgs => FArgs], tupledF: TupledFunction[F, FArgs => R]): GArgs => R = {
59-
(x: GArgs) => tupledF(f)(tupledG(g)(x))
58+
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = {
59+
(x: GArgs) => tf.tuple(f)(tg.tuple(g)(x))
6060
}
6161
```

library/src-3.x/scala/TupledFunction.scala

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,109 +9,109 @@ import scala.annotation.implicitNotFound
99
*/
1010
@implicitNotFound("${F} cannot be tupled as ${G}")
1111
sealed trait TupledFunction[F, G] {
12-
def apply(f: F): G
12+
def tuple(f: F): G
1313
}
1414

1515
package internal {
1616

1717
object TupledFunction {
1818

1919
def tupledFunction0[F, G]: TupledFunction[F, G] = new TupledFunction {
20-
def apply(f: F): G =
20+
def tuple(f: F): G =
2121
((args: Unit) => f.asInstanceOf[() => Any].apply()).asInstanceOf[G]
2222
}
2323

2424
def tupledFunction1[F, G]: TupledFunction[F, G] = new TupledFunction {
25-
def apply(f: F): G =
25+
def tuple(f: F): G =
2626
((args: Tuple1[Any]) => f.asInstanceOf[Any => Any].apply(args._1)).asInstanceOf[G]
2727
}
2828

2929
def tupledFunction2[F, G]: TupledFunction[F, G] = new TupledFunction {
30-
def apply(f: F): G = f.asInstanceOf[Function2[_, _, _]].tupled.asInstanceOf[G]
30+
def tuple(f: F): G = f.asInstanceOf[Function2[_, _, _]].tupled.asInstanceOf[G]
3131
}
3232

3333
def tupledFunction3[F, G]: TupledFunction[F, G] = new TupledFunction {
34-
def apply(f: F): G = f.asInstanceOf[Function3[_, _, _, _]].tupled.asInstanceOf[G]
34+
def tuple(f: F): G = f.asInstanceOf[Function3[_, _, _, _]].tupled.asInstanceOf[G]
3535
}
3636

3737
def tupledFunction4[F, G]: TupledFunction[F, G] = new TupledFunction {
38-
def apply(f: F): G = f.asInstanceOf[Function4[_, _, _, _, _]].tupled.asInstanceOf[G]
38+
def tuple(f: F): G = f.asInstanceOf[Function4[_, _, _, _, _]].tupled.asInstanceOf[G]
3939
}
4040

4141
def tupledFunction5[F, G]: TupledFunction[F, G] = new TupledFunction {
42-
def apply(f: F): G = f.asInstanceOf[Function5[_, _, _, _, _, _]].tupled.asInstanceOf[G]
42+
def tuple(f: F): G = f.asInstanceOf[Function5[_, _, _, _, _, _]].tupled.asInstanceOf[G]
4343
}
4444

4545
def tupledFunction6[F, G]: TupledFunction[F, G] = new TupledFunction {
46-
def apply(f: F): G = f.asInstanceOf[Function6[_, _, _, _, _, _, _]].tupled.asInstanceOf[G]
46+
def tuple(f: F): G = f.asInstanceOf[Function6[_, _, _, _, _, _, _]].tupled.asInstanceOf[G]
4747
}
4848

4949
def tupledFunction7[F, G]: TupledFunction[F, G] = new TupledFunction {
50-
def apply(f: F): G = f.asInstanceOf[Function7[_, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
50+
def tuple(f: F): G = f.asInstanceOf[Function7[_, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
5151
}
5252

5353
def tupledFunction8[F, G]: TupledFunction[F, G] = new TupledFunction {
54-
def apply(f: F): G = f.asInstanceOf[Function8[_, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
54+
def tuple(f: F): G = f.asInstanceOf[Function8[_, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
5555
}
5656

5757
def tupledFunction9[F, G]: TupledFunction[F, G] = new TupledFunction {
58-
def apply(f: F): G = f.asInstanceOf[Function9[_, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
58+
def tuple(f: F): G = f.asInstanceOf[Function9[_, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
5959
}
6060

6161
def tupledFunction10[F, G]: TupledFunction[F, G] = new TupledFunction {
62-
def apply(f: F): G = f.asInstanceOf[Function10[_, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
62+
def tuple(f: F): G = f.asInstanceOf[Function10[_, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
6363
}
6464

6565
def tupledFunction11[F, G]: TupledFunction[F, G] = new TupledFunction {
66-
def apply(f: F): G = f.asInstanceOf[Function11[_, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
66+
def tuple(f: F): G = f.asInstanceOf[Function11[_, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
6767
}
6868

6969
def tupledFunction12[F, G]: TupledFunction[F, G] = new TupledFunction {
70-
def apply(f: F): G = f.asInstanceOf[Function12[_, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
70+
def tuple(f: F): G = f.asInstanceOf[Function12[_, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
7171
}
7272

7373
def tupledFunction13[F, G]: TupledFunction[F, G] = new TupledFunction {
74-
def apply(f: F): G = f.asInstanceOf[Function13[_, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
74+
def tuple(f: F): G = f.asInstanceOf[Function13[_, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
7575
}
7676

7777
def tupledFunction14[F, G]: TupledFunction[F, G] = new TupledFunction {
78-
def apply(f: F): G = f.asInstanceOf[Function14[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
78+
def tuple(f: F): G = f.asInstanceOf[Function14[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
7979
}
8080

8181
def tupledFunction15[F, G]: TupledFunction[F, G] = new TupledFunction {
82-
def apply(f: F): G = f.asInstanceOf[Function15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
82+
def tuple(f: F): G = f.asInstanceOf[Function15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
8383
}
8484

8585
def tupledFunction16[F, G]: TupledFunction[F, G] = new TupledFunction {
86-
def apply(f: F): G = f.asInstanceOf[Function16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
86+
def tuple(f: F): G = f.asInstanceOf[Function16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
8787
}
8888

8989
def tupledFunction17[F, G]: TupledFunction[F, G] = new TupledFunction {
90-
def apply(f: F): G = f.asInstanceOf[Function17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
90+
def tuple(f: F): G = f.asInstanceOf[Function17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
9191
}
9292

9393
def tupledFunction18[F, G]: TupledFunction[F, G] = new TupledFunction {
94-
def apply(f: F): G = f.asInstanceOf[Function18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
94+
def tuple(f: F): G = f.asInstanceOf[Function18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
9595
}
9696

9797
def tupledFunction19[F, G]: TupledFunction[F, G] = new TupledFunction {
98-
def apply(f: F): G = f.asInstanceOf[Function19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
98+
def tuple(f: F): G = f.asInstanceOf[Function19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
9999
}
100100

101101
def tupledFunction20[F, G]: TupledFunction[F, G] = new TupledFunction {
102-
def apply(f: F): G = f.asInstanceOf[Function20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
102+
def tuple(f: F): G = f.asInstanceOf[Function20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
103103
}
104104

105105
def tupledFunction21[F, G]: TupledFunction[F, G] = new TupledFunction {
106-
def apply(f: F): G = f.asInstanceOf[Function21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
106+
def tuple(f: F): G = f.asInstanceOf[Function21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
107107
}
108108

109109
def tupledFunction22[F, G]: TupledFunction[F, G] = new TupledFunction {
110-
def apply(f: F): G = f.asInstanceOf[Function22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
110+
def tuple(f: F): G = f.asInstanceOf[Function22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
111111
}
112112

113113
def tupledFunctionXXL[F, G]: TupledFunction[F, G] = new TupledFunction {
114-
def apply(f: F): G =
114+
def tuple(f: F): G =
115115
((args: TupleXXL) => f.asInstanceOf[FunctionXXL].apply(args.elems)).asInstanceOf[G]
116116
}
117117

tests/run/tupled-function-andThen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object Test {
3333
* @tparam R the return type of G
3434
*/
3535
def (f: F) andThen[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tf: TupledFunction[F, FArgs => GArgs], tg: TupledFunction[G, GArgs => R]): FArgs => R = {
36-
x => tg(g)(tf(f)(x))
36+
x => tg.tuple(g)(tf.tuple(f)(x))
3737
}
3838

3939
}

tests/run/tupled-function-apply.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ object Test {
113113
* @tparam Args the tuple type with the same types as the function arguments of F
114114
* @tparam R the return type of F
115115
*/
116-
def (f: F) apply[F, Args <: Tuple, R](args: Args) given (tupled: TupledFunction[F, Args => R]): R =
117-
tupled(f)(args)
116+
def (f: F) apply[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, Args => R]): R =
117+
tf.tuple(f)(args)
118118
}

tests/run/tupled-function-compose.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object Test {
3434
* @tparam R the return type of F
3535
*/
3636
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = {
37-
x => tf(f)(tg(g)(x))
37+
x => tf.tuple(f)(tg.tuple(g)(x))
3838
}
3939

4040
}

tests/run/tupled-function-extension-method.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ object Test {
3939
def (e: Expr[given Arg => R]) applyGiven[Arg, R](arg: Arg): R = e.x given arg
4040

4141
// Applied to all funtions of arity 2 or more (including more than 22 parameters)
42-
def (e: Expr[F]) apply[F, Args <: Tuple, R](args: Args) given (tupled: TupledFunction[F, Args => R]): R =
43-
tupled(e.x)(args)
44-
def (e: Expr[F]) applyGiven[F, Args <: Tuple, R](args: Args) given (tupled: TupledFunction[F, given Args => R]): R =
45-
tupled(e.x) given args
42+
def (e: Expr[F]) apply[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, Args => R]): R =
43+
tf.tuple(e.x)(args)
44+
def (e: Expr[F]) applyGiven[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, given Args => R]): R =
45+
tf.tuple(e.x) given args
4646

4747
}

tests/run/tupled-function-tupled.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ object Test {
2424
* @tparam Args the tuple type with the same types as the function arguments of F
2525
* @tparam R the return type of F
2626
*/
27-
def (f: F) tupled[F, Args <: Tuple, R] given (tupled: TupledFunction[F, Args => R]): Args => R = tupled(f)
28-
}
27+
def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): Args => R = tf.tuple(f)
28+
}

0 commit comments

Comments
 (0)