Skip to content

Instantly share code, notes, and snippets.

@bwmcadams
Created April 5, 2011 20:58
Show Gist options
  • Save bwmcadams/904538 to your computer and use it in GitHub Desktop.
Save bwmcadams/904538 to your computer and use it in GitHub Desktop.
scala> val x: PartialFunction[String, Unit] = { case "foo" => println("Foo") }
x: PartialFunction[String,Unit] = <function1>
scala> x("foo")
Foo
scala> x("bar")
scala.MatchError: bar
scala> val y: PartialFunction[String, Unit] = { case "bar" => println("Bar") }
y: PartialFunction[String,Unit] = <function1>
scala> y("bar")
Bar
scala> val z = x orElse y
z: PartialFunction[String,Unit] = <function1>
scala> z("foo")
Foo
scala> z("bar")
Bar
scala> z("baz")
scala.MatchError: baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment