Created
August 4, 2011 15:50
-
-
Save CheatEx/1125489 to your computer and use it in GitHub Desktop.
Draft for hs-style function-in-applicative usage
This file contains 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 scalaz._ | |
import Scalaz._ | |
trait AMA[M[_], A] extends PimpedType[M[A]] { | |
//just <*> with a swapped arguments | |
def <@>[X, Y](x: M[X])(implicit ev: A <:< (X=>Y), app: Apply[M], f: Functor[M]): M[Y] = app.apply(value map ev, x) | |
} | |
object Fs { | |
implicit def ValidationAMA[A, E](v: Validation[E, A]) = new AMA[({type l[α]=Validation[E, α]})#l, A] { | |
val value = v | |
} | |
} | |
class AppDemo { | |
import Fs._ | |
def main(args: Array[String]) { | |
println( | |
{(a: Int) => (b: Int) => a+b}.successNel[String] <@> 1.successNel[String] <@> 2.successNel[String] | |
) | |
println( | |
{(a: Int) => (b: Int) => a+b}.successNel[String] <@> "Opps".failNel[Int] <@> "That's wrong".failNel[Int] | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment