@@ -5,12 +5,11 @@ import scala.annotation.implicitNotFound
55/** Type class relating a `FunctionN[..., R]` with an equvalent tupled function `Function1[TupleN[...], R]`
66 *
77 * @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
8+ * @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
109 */
11- @ implicitNotFound(" ${F} cannot be tupled as ${Args} => ${R }" )
12- trait TupledFunction [F , Args <: Tuple , R ] {
13- def applyFunctionTo (f : F , args : Args ): R
10+ @ implicitNotFound(" ${F} cannot be tupled as ${G }" )
11+ trait TupledFunction [F , G ] {
12+ def apply (f : F ): G
1413}
1514
1615/** Module of TupledFunction containing methods for auto function tupling
@@ -37,8 +36,8 @@ object TupledFunction {
3736 * @tparam Args the tuple type with the same types as the function arguments of F
3837 * @tparam R the return type of F
3938 */
40- def (f : F ) apply[F , Args <: Tuple , R ](args : Args ) given (tf : TupledFunction [F , Args , R ]): R =
41- tf.applyFunctionTo(f, args)
39+ def (f : F ) apply[F , Args <: Tuple , R ](args : Args ) given (tupled : TupledFunction [F , Args => R ]): R =
40+ tupled(f)( args)
4241
4342 /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied last
4443 *
@@ -48,7 +47,7 @@ object TupledFunction {
4847 * @tparam GArgs the tuple type with the same types as the function arguments of G
4948 * @tparam R the return type of F
5049 */
51- def (f : F ) compose[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [G , GArgs , FArgs ], TupledFunction [F , FArgs , R ]: GArgs => R = {
50+ def (f : F ) compose[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [G , GArgs => FArgs ], TupledFunction [F , FArgs => R ]: GArgs => R = {
5251 x => f(g(x))
5352 }
5453
@@ -60,7 +59,7 @@ object TupledFunction {
6059 * @tparam GArgs the tuple type with the same types as the function arguments of G and return type of F
6160 * @tparam R the return type of G
6261 */
63- def (f : F ) andThen[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [F , FArgs , GArgs ], TupledFunction [G , GArgs , R ]: FArgs => R = {
62+ def (f : F ) andThen[F , G , FArgs <: Tuple , GArgs <: Tuple , R ](g : G ) given TupledFunction [F , FArgs => GArgs ], TupledFunction [G , GArgs => R ]: FArgs => R = {
6463 x => g(f(x))
6564 }
6665
0 commit comments