From aab959bbe2263962add5da425a312b1ea209692f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 9 Sep 2010 17:05:40 +0000 Subject: 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. --- test/files/run/lift-and-unlift.scala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/files/run/lift-and-unlift.scala (limited to 'test/files/run') 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) + } +} -- cgit v1.2.3