Created
May 13, 2016 14:41
-
-
Save yusefnapora/03863b5f0acc63c3d38f1183462c7af5 to your computer and use it in GitHub Desktop.
Applicative instance for scala Future using cats
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
object Foo { | |
// based on this scalaz version: https://gist.github.com/Fristi/e7139a89e2c66d455e97 | |
implicit def applicativeFuture(implicit executionContext: ExecutionContext) | |
= new Applicative[Future] { | |
override def pure[A](x: A): Future[A] = Future.successful(x) | |
override def ap[A, B](ff: Future[(A) => B])(fa: Future[A]): Future[B] = | |
ff.flatMap(fa.map(_)) | |
override def map[A, B](fa: Future[A])(f: (A) => B): Future[B] = fa.map(f) | |
override def product[A, B](fa: Future[A], fb: Future[B]): Future[(A, B)] = | |
for { | |
a <- fa | |
b <- fb | |
} yield (a, b) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment