summaryrefslogtreecommitdiff
path: root/src/library/scala/Function2.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-04-27 07:24:46 -0700
committerPaul Phillips <paulp@improving.org>2012-04-27 07:24:46 -0700
commit1c3f66b6f2d41c02cc2bc32cb696aafa56b71176 (patch)
treeafd2ec64dc39ac29c2fc15221e431d2d8548a9e7 /src/library/scala/Function2.scala
parent57574bb10833e90338bd0eadef9dabe260b8afda (diff)
downloadscala-1c3f66b6f2d41c02cc2bc32cb696aafa56b71176.tar.gz
scala-1c3f66b6f2d41c02cc2bc32cb696aafa56b71176.tar.bz2
scala-1c3f66b6f2d41c02cc2bc32cb696aafa56b71176.zip
Revert "Moved ancillary methods off specialized traits."
This reverts commit 1d0372f84f9a7325a47beb55169cc454895ef74b. I forgot about polymorphic dispatch. Have to seek another way.
Diffstat (limited to 'src/library/scala/Function2.scala')
-rw-r--r--src/library/scala/Function2.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/library/scala/Function2.scala b/src/library/scala/Function2.scala
index 5ea2b411bb..cacb96ef5d 100644
--- a/src/library/scala/Function2.scala
+++ b/src/library/scala/Function2.scala
@@ -37,6 +37,20 @@ trait Function2[@specialized(scala.Int, scala.Long, scala.Double) -T1, @speciali
* @return the result of function application.
*/
def apply(v1: T1, v2: T2): R
+ /** Creates a curried version of this function.
+ *
+ * @return a function `f` such that `f(x1)(x2) == apply(x1, x2)`
+ */ def curried: T1 => T2 => R = {
+ (x1: T1) => (x2: T2) => apply(x1, x2)
+ }
+ /** Creates a tupled version of this function: instead of 2 arguments,
+ * it accepts a single [[scala.Tuple2]] argument.
+ *
+ * @return a function `f` such that `f((x1, x2)) == f(Tuple2(x1, x2)) == apply(x1, x2)`
+ */
+ def tupled: Tuple2[T1, T2] => R = {
+ case Tuple2(x1, x2) => apply(x1, x2)
+ }
override def toString() = "<function2>"
}