Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Forked from tomwadeson/Callback.scala
Created March 23, 2016 01:26
Show Gist options
  • Save missingfaktor/c40e0df3758a86068564 to your computer and use it in GitHub Desktop.
Save missingfaktor/c40e0df3758a86068564 to your computer and use it in GitHub Desktop.
scala> case class Callback[A](f: (A => Unit) => Unit) {
| def map[B](g: A => B): Callback[B] = Callback { (h: B => Unit) => f(a => h(g(a))) }
| def flatMap[B](g: A => Callback[B]): Callback[B] = Callback { (h: B => Unit) => f(a => g(a).f(b => h(b))) }
| }
defined class Callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment