Created
June 21, 2012 16:28
-
-
Save agemooij/2966846 to your computer and use it in GitHub Desktop.
Akka: logging any received message
This file contains hidden or 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
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
def wrap(partial: PartialFunction[Any, Unit]): PartialFunction[Any, Unit] = new PartialFunction[Any, Unit] { | |
def isDefinedAt(a: Any): Boolean = partial.isDefinedAt(a) | |
def apply(a: Any): Unit = { | |
println("----> received " + a) | |
partial.apply(a) | |
} | |
} | |
// Exiting paste mode, now interpreting. | |
wrap: (partial: PartialFunction[Any,Unit])PartialFunction[Any,Unit] | |
scala> wrap { | |
| case i: Int => println("An int!") | |
| case s: String => println("A String!") | |
| case _ => println("Something else!") | |
| } | |
res0: PartialFunction[Any,Unit] = <function1> | |
scala> res0(3) | |
----> received 3 | |
An int! | |
scala> res0("bla") | |
----> received bla | |
A String! | |
scala> res0(4.89) | |
----> received 4.89 | |
Something else! | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment