Created
October 4, 2013 14:04
-
-
Save diegovar/6826429 to your computer and use it in GitHub Desktop.
testing partial function composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
class P { | |
def receive: PartialFunction[String, Any] = { | |
case _ => "Default" | |
} | |
} | |
trait Partial2 extends P { | |
private def p2Receive: PartialFunction[String, Any] = { | |
case "1" => "1" | |
} | |
abstract override def receive = p2Receive orElse super.receive | |
} | |
object Main { | |
def main(args: Array[String]) { | |
val p = new P with Partial2 | |
println(p.receive("1")) | |
println(p.receive("2")) | |
assert(p.receive("1") == "1") | |
assert(p.receive("2") == "Default") | |
} | |
} | |
Main.main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment