Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected class EventHandler[Event, +Result](callback: Event => Result) {
- def apply(event: Event) = // [... code omitted ...]
- def applyFromHistory(event: Event) = callback(event)
- }
- protected def handler[A, B](callback: A => B) = new EventHandler(callback)
- implicit protected def handlerToPartialFunction[A, B](handler: EventHandler[A, B])(implicit m: Manifest[A]) =
- new PartialFunction[AnyRef, B] {
- def isDefinedAt(event: AnyRef) = m.erasure.isInstance(event)
- def apply(event: AnyRef) = handler.applyFromHistory(event.asInstanceOf[A])
- }
Add Comment
Please, Sign In to add comment