Created
August 5, 2013 01:32
-
-
Save hisui/6152881 to your computer and use it in GitHub Desktop.
Enables Play2's FunctionalBuilder for Scala10's Try[A].
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
import play.api.libs.functional._ | |
import scala.language.higherKinds | |
import scala.util.{Success, Try} | |
object Play2FunctionalImplicitConversions { | |
implicit val tryApplicative:Applicative[Try] = | |
new Applicative[Try] { | |
def apply[A, B](mf: Try[(A) => B], ma: Try[A]): Try[B] = mf.flatMap(f => ma.map(f(_))) | |
def pure[A](a: A): Try[A] = Success(a) | |
def map[A, B](m: Try[A], f: (A) => B): Try[B] = m.map(f) | |
} | |
implicit val tryVariant:Variant[Try] = new Variant[Try] {} | |
implicit def applicativeToFunctor[M[_]](implicit ev:Applicative[M]):Functor[M] = new Functor[M] { | |
def fmap[A, B](m: M[A], f: (A) => B): M[B] = ev.map(m, f) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment