Created
May 14, 2013 14:58
-
-
Save ThiporKong/5576580 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
trait Run[F[_]] { | |
def apply[I](request: F[I]): (I, Run[F]) | |
def unit[I](i: I): F[I] // needed to be able to implement Monad[F] | |
} | |
def runnerMonad[F[_]](requestRunner: Run[F]) = new Monad[F] { | |
// keep the current state of the runner here | |
var runner = requestRunner | |
def unit[A](a: => A): F[A] = runner.unit(a) | |
def flatMap[A, B](ma: F[A])(f: A => F[B]): F[B] = { | |
runner.apply(ma) match { case (a, ma1) => runner = ma1; f(a) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment