Created
February 2, 2013 04:23
-
-
Save tpolecat/4696104 to your computer and use it in GitHub Desktop.
This file contains 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
class Box[A] { | |
private var waiters = Queue[A => Unit]() | |
def watch(f:A => Unit) = waiters = waiters :+ f | |
def put(a:A) = waiters.foreach(_(a)) | |
} | |
val b = new Box[String] | |
for (i <- 1 to 5) | |
b.watch(s => println(s + " " + i)) | |
b.put("foo") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment