Skip to content

Commit 3c2005d

Browse files
committed
Seal TupledFunction to only have instances in internal
1 parent 22162be commit 3c2005d

File tree

3 files changed

+109
-106
lines changed

3 files changed

+109
-106
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The type class `TupleFunction` provides a way to abstract directly over function
1717
* @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
1818
*/
1919
@implicitNotFound("${F} cannot be tupled as ${G}")
20-
trait TupledFunction[F, G] {
20+
sealed trait TupledFunction[F, G] {
2121
def apply(f: F): G
2222
}
2323
```

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

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,113 @@ import scala.annotation.implicitNotFound
88
* @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
99
*/
1010
@implicitNotFound("${F} cannot be tupled as ${G}")
11-
trait TupledFunction[F, G] {
11+
sealed trait TupledFunction[F, G] {
1212
def apply(f: F): G
1313
}
14+
15+
package internal {
16+
17+
object TupledFunction {
18+
19+
def tupledFunction0[F, G]: TupledFunction[F, G] = new TupledFunction {
20+
def apply(f: F): G =
21+
((args: Unit) => f.asInstanceOf[() => Any].apply()).asInstanceOf[G]
22+
}
23+
24+
def tupledFunction1[F, G]: TupledFunction[F, G] = new TupledFunction {
25+
def apply(f: F): G =
26+
((args: Tuple1[Any]) => f.asInstanceOf[Any => Any].apply(args._1)).asInstanceOf[G]
27+
}
28+
29+
def tupledFunction2[F, G]: TupledFunction[F, G] = new TupledFunction {
30+
def apply(f: F): G = f.asInstanceOf[Function2[_, _, _]].tupled.asInstanceOf[G]
31+
}
32+
33+
def tupledFunction3[F, G]: TupledFunction[F, G] = new TupledFunction {
34+
def apply(f: F): G = f.asInstanceOf[Function3[_, _, _, _]].tupled.asInstanceOf[G]
35+
}
36+
37+
def tupledFunction4[F, G]: TupledFunction[F, G] = new TupledFunction {
38+
def apply(f: F): G = f.asInstanceOf[Function4[_, _, _, _, _]].tupled.asInstanceOf[G]
39+
}
40+
41+
def tupledFunction5[F, G]: TupledFunction[F, G] = new TupledFunction {
42+
def apply(f: F): G = f.asInstanceOf[Function5[_, _, _, _, _, _]].tupled.asInstanceOf[G]
43+
}
44+
45+
def tupledFunction6[F, G]: TupledFunction[F, G] = new TupledFunction {
46+
def apply(f: F): G = f.asInstanceOf[Function6[_, _, _, _, _, _, _]].tupled.asInstanceOf[G]
47+
}
48+
49+
def tupledFunction7[F, G]: TupledFunction[F, G] = new TupledFunction {
50+
def apply(f: F): G = f.asInstanceOf[Function7[_, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
51+
}
52+
53+
def tupledFunction8[F, G]: TupledFunction[F, G] = new TupledFunction {
54+
def apply(f: F): G = f.asInstanceOf[Function8[_, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
55+
}
56+
57+
def tupledFunction9[F, G]: TupledFunction[F, G] = new TupledFunction {
58+
def apply(f: F): G = f.asInstanceOf[Function9[_, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
59+
}
60+
61+
def tupledFunction10[F, G]: TupledFunction[F, G] = new TupledFunction {
62+
def apply(f: F): G = f.asInstanceOf[Function10[_, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
63+
}
64+
65+
def tupledFunction11[F, G]: TupledFunction[F, G] = new TupledFunction {
66+
def apply(f: F): G = f.asInstanceOf[Function11[_, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
67+
}
68+
69+
def tupledFunction12[F, G]: TupledFunction[F, G] = new TupledFunction {
70+
def apply(f: F): G = f.asInstanceOf[Function12[_, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
71+
}
72+
73+
def tupledFunction13[F, G]: TupledFunction[F, G] = new TupledFunction {
74+
def apply(f: F): G = f.asInstanceOf[Function13[_, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
75+
}
76+
77+
def tupledFunction14[F, G]: TupledFunction[F, G] = new TupledFunction {
78+
def apply(f: F): G = f.asInstanceOf[Function14[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
79+
}
80+
81+
def tupledFunction15[F, G]: TupledFunction[F, G] = new TupledFunction {
82+
def apply(f: F): G = f.asInstanceOf[Function15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
83+
}
84+
85+
def tupledFunction16[F, G]: TupledFunction[F, G] = new TupledFunction {
86+
def apply(f: F): G = f.asInstanceOf[Function16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
87+
}
88+
89+
def tupledFunction17[F, G]: TupledFunction[F, G] = new TupledFunction {
90+
def apply(f: F): G = f.asInstanceOf[Function17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
91+
}
92+
93+
def tupledFunction18[F, G]: TupledFunction[F, G] = new TupledFunction {
94+
def apply(f: F): G = f.asInstanceOf[Function18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
95+
}
96+
97+
def tupledFunction19[F, G]: TupledFunction[F, G] = new TupledFunction {
98+
def apply(f: F): G = f.asInstanceOf[Function19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
99+
}
100+
101+
def tupledFunction20[F, G]: TupledFunction[F, G] = new TupledFunction {
102+
def apply(f: F): G = f.asInstanceOf[Function20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
103+
}
104+
105+
def tupledFunction21[F, G]: TupledFunction[F, G] = new TupledFunction {
106+
def apply(f: F): G = f.asInstanceOf[Function21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
107+
}
108+
109+
def tupledFunction22[F, G]: TupledFunction[F, G] = new TupledFunction {
110+
def apply(f: F): G = f.asInstanceOf[Function22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]].tupled.asInstanceOf[G]
111+
}
112+
113+
def tupledFunctionXXL[F, G]: TupledFunction[F, G] = new TupledFunction {
114+
def apply(f: F): G =
115+
((args: TupleXXL) => f.asInstanceOf[FunctionXXL].apply(args.elems)).asInstanceOf[G]
116+
}
117+
118+
}
119+
120+
}

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

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)