summaryrefslogtreecommitdiff
path: root/src/library/scala/Function1.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/Function1.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/Function1.scala')
-rw-r--r--src/library/scala/Function1.scala16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala
index a4391c1509..8995ef912b 100644
--- a/src/library/scala/Function1.scala
+++ b/src/library/scala/Function1.scala
@@ -38,5 +38,21 @@ trait Function1[@specialized(scala.Int, scala.Long, scala.Float, scala.Double, s
*/
def apply(v1: T1): R
+ /** Composes two instances of Function1 in a new Function1, with this function applied last.
+ *
+ * @tparam A the type to which function `g` can be applied
+ * @param g a function A => T1
+ * @return a new function `f` such that `f(x) == apply(g(x))`
+ */
+ def compose[A](g: A => T1): A => R = { x => apply(g(x)) }
+
+ /** Composes two instances of Function1 in a new Function1, with this function applied first.
+ *
+ * @tparam A the result type of function `g`
+ * @param g a function R => A
+ * @return a new function `f` such that `f(x) == g(apply(x))`
+ */
+ def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) }
+
override def toString() = "<function1>"
}