Skip to content

Instantly share code, notes, and snippets.

@stew
Created October 16, 2012 17:29
Show Gist options
  • Save stew/3900735 to your computer and use it in GitHub Desktop.
Save stew/3900735 to your computer and use it in GitHub Desktop.
scalaz instances for an Akka Future
import akka.dispatch.ExecutionContext
import akka.dispatch.Future
import scalaz._
import Scalaz._
object FutureInstances {
implicit val futureFunctor : Functor[Future] = new Functor[Future] {
override def map[A,B](fa: Future[A])(f: A=>B) = fa map f
}
implicit def futureMonad(implicit executor: ExecutionContext) : Monad[Future] with Zip[Future] = new Monad[Future] with Zip[Future] {
override def bind[A,B](fa: Future[A])(f: A=>Future[B]) = fa flatMap f
override def point[A](a: => A) = Future(a)
override def zip[A, B](a: => Future[A], b: => Future[B]) =
for {
x <- a
y <- b
} yield (x, y)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment