Skip to content

Instantly share code, notes, and snippets.

@travisbrown
Created April 15, 2015 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travisbrown/b937a4681ed9e47d39f3 to your computer and use it in GitHub Desktop.
Save travisbrown/b937a4681ed9e47d39f3 to your computer and use it in GitHub Desktop.
import scalaz._, Free.Trampoline, Scalaz._
sealed trait Command[T]
case class Wait(ms: Long) extends Command[Unit]
case object Evaluator extends (Command ~> Trampoline) {
override def apply[T](cmd: Command[T]) = cmd match {
case Wait(t) => Trampoline.done(Thread.sleep(t))
}
}
object Api {
def sleep(ms: Long): Free.FreeC[Command, Unit] = Free.liftFC(Wait(ms))
}
val sleep: Free.FreeC[Command, Unit] =
Api.sleep(1).flatMap { _ => sleep }
Free.runFC(sleep)(Evaluator).run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment