Skip to content

Commit 15aa152

Browse files
committed
Add documentation
1 parent 9a92ec7 commit 15aa152

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

library/src-3.x/dotty/DottyPredef.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ object DottyPredef {
3939
inline def the[T] given (x: T): x.type = x
4040

4141
/** Creates a tupled version of this function: instead of N arguments,
42-
* it accepts a single [[scala.Tuple]] argument.
43-
*/
42+
* it accepts a single [[scala.Tuple]] argument.
43+
*
44+
* @tparam F the function type
45+
* @tparam Args the tuple type with the same types as the function arguments of F
46+
* @tparam R the return type of F
47+
*/
4448
def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args, R]): Args => R = {
4549
x => tf.applyFunctionTo(f, x)
4650
}

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,48 @@ package scala
22

33
import 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}")
612
trait TupledFunction[F, Args <: Tuple, R] {
713
def applyFunctionTo(f: F, args: Args): R
814
}
915

1016
object 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

Comments
 (0)