@@ -5,12 +5,11 @@ import scala.annotation.implicitNotFound
5
5
/** Type class relating a `FunctionN[..., R]` with an equvalent tupled function `Function1[TupleN[...], R]`
6
6
*
7
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
8
+ * @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
10
9
*/
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
14
13
}
15
14
16
15
/** Module of TupledFunction containing methods for auto function tupling
@@ -37,8 +36,8 @@ object TupledFunction {
37
36
* @tparam Args the tuple type with the same types as the function arguments of F
38
37
* @tparam R the return type of F
39
38
*/
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)
42
41
43
42
/** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied last
44
43
*
@@ -48,7 +47,7 @@ object TupledFunction {
48
47
* @tparam GArgs the tuple type with the same types as the function arguments of G
49
48
* @tparam R the return type of F
50
49
*/
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 = {
52
51
x => f(g(x))
53
52
}
54
53
@@ -60,7 +59,7 @@ object TupledFunction {
60
59
* @tparam GArgs the tuple type with the same types as the function arguments of G and return type of F
61
60
* @tparam R the return type of G
62
61
*/
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 = {
64
63
x => g(f(x))
65
64
}
66
65
0 commit comments