diff options
author | Pavel Pavlov <pavel.e.pavlov@gmail.com> | 2012-01-16 07:57:09 +0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-03-30 09:19:03 +0200 |
commit | 66b47e1a8c11196d648ed5a98f934a1c65203a65 (patch) | |
tree | 69d808bc33be23f35ffc06755bce492a5463f779 /test/files/run/lift-and-unlift.scala | |
parent | 71392585dc56950287135ac2582b516d7971bfbc (diff) | |
download | scala-66b47e1a8c11196d648ed5a98f934a1c65203a65.tar.gz scala-66b47e1a8c11196d648ed5a98f934a1c65203a65.tar.bz2 scala-66b47e1a8c11196d648ed5a98f934a1c65203a65.zip |
a fast, functional PartialFunction implementation
runtime.AbstractPartialFunction provides a default implementation
for the new-style partial function. In principle this class is only
subclassed by compiler-generated partial functions arising from matches.
Either
- the apply method (old-style partialfun) or
- the applyOrElse method (current scheme)
must be overridden, and the isDefinedAt method implemented.
The applyOrElse method implementation is provided to ease the
transition from the old scheme, since starr still generates
old-style PartialFunctions, but locker's library has the
new AbstractPartialFunction.
Thus, this implementation is intended as a drop-in replacement for the
old partial function, and does not require changes to the compiler.
(compiler patches, both for old and new-style pattern matching, follow)
- runtime.AbstractPartialFunction is based on PartialFunction.WithDefault
Original version of FunctionWithDefault by Odersky
(http://article.gmane.org/gmane.comp.lang.scala.internals/4032)
- better performance for OrElse#applyOrElse, OrElse#lift, PF.cond
- new combinator methods: PF#run, PF#runWith, PF.apply
authored by @pavelpavlov, refactored by @adriaanm, review by @paulp
Diffstat (limited to 'test/files/run/lift-and-unlift.scala')
-rw-r--r-- | test/files/run/lift-and-unlift.scala | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/test/files/run/lift-and-unlift.scala b/test/files/run/lift-and-unlift.scala index b944c70155..a4a5d9502e 100644 --- a/test/files/run/lift-and-unlift.scala +++ b/test/files/run/lift-and-unlift.scala @@ -2,7 +2,7 @@ import Function.unlift object Test { def evens1(x: Int) = if (x % 2 == 0) Some(x) else None - def evens2: PartialFunction[Int, Int] = { + val evens2: PartialFunction[Int, Int] = { case x if x % 2 == 0 => x } @@ -21,7 +21,7 @@ object Test { }) assert(f1 eq f3.lift) - // Hmm, why is this not true: - // assert(f2 eq f4.lift) + assert(f4 eq unlift(f2)) + assert(f4 eq evens2) } } |