From 15aa15232de113b336ddf307eaf5b6af9675b368 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 27 May 2019 10:59:09 +0200 Subject: [PATCH] Add documentation --- library/src-3.x/dotty/DottyPredef.scala | 8 ++++-- library/src-3.x/scala/TupledFunction.scala | 31 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/library/src-3.x/dotty/DottyPredef.scala b/library/src-3.x/dotty/DottyPredef.scala index 6fc437404fc3..c06054c6de57 100644 --- a/library/src-3.x/dotty/DottyPredef.scala +++ b/library/src-3.x/dotty/DottyPredef.scala @@ -39,8 +39,12 @@ object DottyPredef { inline def the[T] given (x: T): x.type = x /** Creates a tupled version of this function: instead of N arguments, - * it accepts a single [[scala.Tuple]] argument. - */ + * it accepts a single [[scala.Tuple]] argument. + * + * @tparam F the function type + * @tparam Args the tuple type with the same types as the function arguments of F + * @tparam R the return type of F + */ def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args, R]): Args => R = { x => tf.applyFunctionTo(f, x) } diff --git a/library/src-3.x/scala/TupledFunction.scala b/library/src-3.x/scala/TupledFunction.scala index 7b056731104a..2233d0da9e8c 100644 --- a/library/src-3.x/scala/TupledFunction.scala +++ b/library/src-3.x/scala/TupledFunction.scala @@ -2,6 +2,12 @@ package scala import scala.annotation.implicitNotFound +/** Type class relating a `FunctionN[..., R]` with an equvalent tupled function `Function1[TupleN[...], R]` + * + * @tparam F a function type + * @tparam Args a tuple type with the same types as the function arguments of F + * @tparam R the return type of F + */ @implicitNotFound("${F} cannot be tupled as ${Args} => ${R}") trait TupledFunction[F, Args <: Tuple, R] { def applyFunctionTo(f: F, args: Args): R @@ -9,16 +15,35 @@ trait TupledFunction[F, Args <: Tuple, R] { object TupledFunction { - /** Apply this function to with each element of the tuple as a parameter */ + /** Apply this function to with each element of the tuple as a parameter + * + * @tparam F the function type + * @tparam Args the tuple type with the same types as the function arguments of F + * @tparam R the return type of F + */ def (f: F) apply[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, Args, R]): R = tf.applyFunctionTo(f, args) - /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied last */ + /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied last + * + * @tparam F a function type + * @tparam G a function type + * @tparam FArgs the tuple type with the same types as the function arguments of F and return type of G + * @tparam GArgs the tuple type with the same types as the function arguments of G + * @tparam R the return type of F + */ def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given TupledFunction[G, GArgs, FArgs], TupledFunction[F, FArgs, R]: GArgs => R = { x => f(g(x)) } - /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied first */ + /** Composes two instances of TupledFunctions in a new TupledFunctions, with this function applied first + * + * @tparam F a function type + * @tparam G a function type + * @tparam FArgs the tuple type with the same types as the function arguments of F + * @tparam GArgs the tuple type with the same types as the function arguments of G and return type of F + * @tparam R the return type of G + */ def (f: F) andThen[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given TupledFunction[F, FArgs, GArgs], TupledFunction[G, GArgs, R]: FArgs => R = { x => g(f(x)) }