Skip to content

Commit

Permalink
Rename TupledFunction.{tuple|untuple} to tupled and untupled
Browse files Browse the repository at this point in the history
To have the same naming convention as scala.Function.{tupled|untupled}
  • Loading branch information
nicolasstucki committed May 28, 2019
1 parent 5e209f5 commit 9507c1f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 64 deletions.
12 changes: 6 additions & 6 deletions docs/docs/reference/other-new-features/tupled-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Now that we have functions and tuples generalized to [arities above 22](https://
The type class `TupleFunction` provides a way to abstract directly over a function of any arity converting it to an equivalent function that receives all arguments in a single tuple.

```scala
/** Type class relating a `FunctionN[..., R]` with an equvalent tupled function `Function1[TupleN[...], R]`
/** Type class relating a `FunctionN[..., R]` with an equivalent tupled function `Function1[TupleN[...], R]`
*
* @tparam F a function type
* @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
*/
@implicitNotFound("${F} cannot be tupled as ${G}")
sealed trait TupledFunction[F, G] {
def tuple(f: F): G
def untuple(g: G): F
def tupled(f: F): G
def untupled(g: G): F
}
```

Expand All @@ -43,7 +43,7 @@ Examples
* @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 = tf.tuple(f)
def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): Args => R = tf.tupled(f)
```

`TupledFunction` can be used to generalize the `Function.untupled` methods to functions of any arities ([full example](https://github.com/lampepfl/dotty/tests/run/tupled-function-untupled.scala))
Expand All @@ -58,7 +58,7 @@ def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]):
* @tparam Args the tuple type with the same types as the function arguments of F
* @tparam R the return type of F
*/
def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): F = tf.untuple(f)
def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): F = tf.untupled(f)
```

`TupledFunction` can also be used to generalize the [`Tuple1.compose`](https://github.com/lampepfl/dotty/tests/run/tupled-function-compose.scala) and [`Tuple1.andThen`](https://github.com/lampepfl/dotty/tests/run/tupled-function-andThen.scala) methods to compose functions of larger arities and with functions that return tuples.
Expand All @@ -73,6 +73,6 @@ def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Ar
* @tparam R the return type of F
*/
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = {
(x: GArgs) => tf.tuple(f)(tg.tuple(g)(x))
(x: GArgs) => tf.tupled(f)(tg.tupled(g)(x))
}
```
102 changes: 51 additions & 51 deletions library/src-3.x/scala/TupledFunction.scala

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/run/tupled-function-andThen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Test {
* @tparam R the return type of G
*/
def (f: F) andThen[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tf: TupledFunction[F, FArgs => GArgs], tg: TupledFunction[G, GArgs => R]): FArgs => R = {
x => tg.tuple(g)(tf.tuple(f)(x))
x => tg.tupled(g)(tf.tupled(f)(x))
}

}
2 changes: 1 addition & 1 deletion tests/run/tupled-function-apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ object Test {
* @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.tuple(f)(args)
tf.tupled(f)(args)
}
2 changes: 1 addition & 1 deletion tests/run/tupled-function-compose.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object Test {
* @tparam R the return type of F
*/
def (f: F) compose[F, G, FArgs <: Tuple, GArgs <: Tuple, R](g: G) given (tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = {
x => tf.tuple(f)(tg.tuple(g)(x))
x => tf.tupled(f)(tg.tupled(g)(x))
}

}
4 changes: 2 additions & 2 deletions tests/run/tupled-function-extension-method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object Test {

// Applied to all funtions of arity 2 or more (including more than 22 parameters)
def (e: Expr[F]) apply[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, Args => R]): R =
tf.tuple(e.x)(args)
tf.tupled(e.x)(args)
def (e: Expr[F]) applyGiven[F, Args <: Tuple, R](args: Args) given (tf: TupledFunction[F, given Args => R]): R =
tf.tuple(e.x) given args
tf.tupled(e.x) given args

}
2 changes: 1 addition & 1 deletion tests/run/tupled-function-tupled.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ object Test {
* @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 = tf.tuple(f)
def (f: F) tupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): Args => R = tf.tupled(f)
}
2 changes: 1 addition & 1 deletion tests/run/tupled-function-untupled.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ object Test {
* @tparam Args the tuple type with the same types as the function arguments of F
* @tparam R the return type of F
*/
def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): F = tf.untuple(f)
def (f: Args => R) untupled[F, Args <: Tuple, R] given (tf: TupledFunction[F, Args => R]): F = tf.untupled(f)
}

0 comments on commit 9507c1f

Please sign in to comment.