@@ -2,23 +2,48 @@ package scala
22
33import scala .annotation .implicitNotFound
44
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+ */
511@ implicitNotFound(" ${F} cannot be tupled as ${Args} => ${R}" )
612trait TupledFunction [F , Args <: Tuple , R ] {
713 def applyFunctionTo (f : F , args : Args ): R
814}
915
1016object TupledFunction {
1117
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+ */
1324 def (f : F ) apply[F , Args <: Tuple , R ](args : Args ) given (tf : TupledFunction [F , Args , R ]): R =
1425 tf.applyFunctionTo(f, args)
1526
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+ */
1735 def (f : F ) compose[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [G , GArgs , FArgs ], TupledFunction [F , FArgs , R ]: GArgs => R = {
1836 x => f(g(x))
1937 }
2038
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+ */
2247 def (f : F ) andThen[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [F , FArgs , GArgs ], TupledFunction [G , GArgs , R ]: FArgs => R = {
2348 x => g(f(x))
2449 }
0 commit comments