blob: 859ec02f999f616c0f696aaf9da3485a1c1156b3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)
}
}
|