@@ -2,23 +2,48 @@ package scala
2
2
3
3
import scala .annotation .implicitNotFound
4
4
5
+ /** Type class relating a `FunctionN[..., R]` with an equvalent tupled function `Function1[TupleN[...], R]`
6
+ *
7
+ * @tparam F a function type
8
+ * @tparam Args a tuple type with the same types as the function arguments of F
9
+ * @tparam R the return type of F
10
+ */
5
11
@ implicitNotFound(" ${F} cannot be tupled as ${Args} => ${R}" )
6
12
trait TupledFunction [F , Args <: Tuple , R ] {
7
13
def applyFunctionTo (f : F , args : Args ): R
8
14
}
9
15
10
16
object TupledFunction {
11
17
12
- /** Apply this function to with each element of the tuple as a parameter */
18
+ /** Apply this function to with each element of the tuple as a parameter
19
+ *
20
+ * @tparam F the function type
21
+ * @tparam Args the tuple type with the same types as the function arguments of F
22
+ * @tparam R the return type of F
23
+ */
13
24
def (f : F ) apply[F , Args <: Tuple , R ](args : Args ) given (tf : TupledFunction [F , Args , R ]): R =
14
25
tf.applyFunctionTo(f, args)
15
26
16
- /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied last */
27
+ /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied last
28
+ *
29
+ * @tparam F a function type
30
+ * @tparam G a function type
31
+ * @tparam FArgs the tuple type with the same types as the function arguments of F and return type of G
32
+ * @tparam GArgs the tuple type with the same types as the function arguments of G
33
+ * @tparam R the return type of F
34
+ */
17
35
def (f : F ) compose[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [G , GArgs , FArgs ], TupledFunction [F , FArgs , R ]: GArgs => R = {
18
36
x => f(g(x))
19
37
}
20
38
21
- /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied first */
39
+ /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied first
40
+ *
41
+ * @tparam F a function type
42
+ * @tparam G a function type
43
+ * @tparam FArgs the tuple type with the same types as the function arguments of F
44
+ * @tparam GArgs the tuple type with the same types as the function arguments of G and return type of F
45
+ * @tparam R the return type of G
46
+ */
22
47
def (f : F ) andThen[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [F , FArgs , GArgs ], TupledFunction [G , GArgs , R ]: FArgs => R = {
23
48
x => g(f(x))
24
49
}
0 commit comments