Guest User

Untitled

a guest
May 20th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.25 KB | None | 0 0
  1. trait EventSource[+T] {
  2.   private[this] val listeners = Set[T => Unit]()
  3.  
  4.   def observe(f: T => Unit) = {
  5.     listeners += f
  6.     new { def unregister() { listeners.remove(f) } }
  7.   }
  8.  
  9.   def raise[U <: T](x: U) {
  10.     listeners.foreach(_(x))
  11.   }
  12. }
Add Comment
Please, Sign In to add comment