Guest User

Untitled

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. protected class EventHandler[Event, +Result](callback: Event => Result) {
  2. def apply(event: Event) = // [... code omitted ...]
  3.  
  4. def applyFromHistory(event: Event) = callback(event)
  5. }
  6.  
  7. protected def handler[A, B](callback: A => B) = new EventHandler(callback)
  8.  
  9. implicit protected def handlerToPartialFunction[A, B](handler: EventHandler[A, B])(implicit m: Manifest[A]) =
  10. new PartialFunction[AnyRef, B] {
  11. def isDefinedAt(event: AnyRef) = m.erasure.isInstance(event)
  12.  
  13. def apply(event: AnyRef) = handler.applyFromHistory(event.asInstanceOf[A])
  14. }
Add Comment
Please, Sign In to add comment