Skip to content

Instantly share code, notes, and snippets.

@CheatEx
Created August 4, 2011 15:50
Show Gist options
  • Save CheatEx/1125489 to your computer and use it in GitHub Desktop.
Save CheatEx/1125489 to your computer and use it in GitHub Desktop.
Draft for hs-style function-in-applicative usage
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