Skip to content

Instantly share code, notes, and snippets.

@diegovar
Created October 4, 2013 14:04
Show Gist options
  • Save diegovar/6826429 to your computer and use it in GitHub Desktop.
Save diegovar/6826429 to your computer and use it in GitHub Desktop.
testing partial function composition
#!/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