Skip to content

Instantly share code, notes, and snippets.

@gszeliga
Created February 18, 2015 23:10
Show Gist options
  • Save gszeliga/be710f6bfe9f2d696ef2 to your computer and use it in GitHub Desktop.
Save gszeliga/be710f6bfe9f2d696ef2 to your computer and use it in GitHub Desktop.
def applicativeBuilder[E] = new Applicative[({type f[x] = BuildStep[E, x]})#f] {
def unit[A](a: A) = Continue(a)
override def map2[A, B, C](fa: BuildStep[E, A], fb: BuildStep[E, B])(f: (A, B) => C) = {
(fa, fb) match{
case (Continue(a), Continue(b)) => Continue(f(a,b))
case (Failure(e1), Failure(e2)) => Failure(e1)
case (f @ Failure(_), _) => f
case (_, f @ Failure(_)) => f
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment