summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-09-09 17:05:40 +0000
committerPaul Phillips <paulp@improving.org>2010-09-09 17:05:40 +0000
commitaab959bbe2263962add5da425a312b1ea209692f (patch)
tree94f2b8d4779344645e924f015c3ebc450097d744 /test/files/run
parent5a150395e7a3ff7e2795a044ae302702a2e0c904 (diff)
downloadscala-aab959bbe2263962add5da425a312b1ea209692f.tar.gz
scala-aab959bbe2263962add5da425a312b1ea209692f.tar.bz2
scala-aab959bbe2263962add5da425a312b1ea209692f.zip
Proposed implementation of 'unlift' on Function...
Proposed implementation of 'unlift' on Function1, the inverse function of PartialFunction#lift. Review by rytz and other interested parties. References #3825, but not closing until this is further considered.
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/lift-and-unlift.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/files/run/lift-and-unlift.scala b/test/files/run/lift-and-unlift.scala
new file mode 100644
index 0000000000..859ec02f99
--- /dev/null
+++ b/test/files/run/lift-and-unlift.scala
@@ -0,0 +1,25 @@
+object Test {
+ def evens1(x: Int) = if (x % 2 == 0) Some(x) else None
+ def evens2: PartialFunction[Int, Int] = {
+ case x if x % 2 == 0 => x
+ }
+
+ def main(args: Array[String]): Unit = {
+ val f1 = evens1 _
+ val f2 = evens2.lift
+
+ assert(1 to 10 forall (x => f1(x) == f2(x)))
+
+ val f3 = f1.unlift
+ val f4 = f2.unlift
+
+ assert(1 to 10 forall { x =>
+ if (!f3.isDefinedAt(x)) !f4.isDefinedAt(x)
+ else f3(x) == f4(x)
+ })
+
+ assert(f1 eq f3.lift)
+ // Hmm, why is this not true:
+ // assert(f2 eq f4.lift)
+ }
+}