Skip to content

Instantly share code, notes, and snippets.

@gszeliga
Created February 24, 2015 22:14
Show Gist options
  • Save gszeliga/e54930e6a2013c43a804 to your computer and use it in GitHub Desktop.
Save gszeliga/e54930e6a2013c43a804 to your computer and use it in GitHub Desktop.
final class SmartBuilder[A,B](val f: BuildStep[Throwable,A => B])
{
def @> [E <: Throwable](step: BuildStep[E,A])(implicit applicative: Applicative[({type f[x] = BuildStep[Throwable, x]})#f]) = {
applicative.apply(f)(step)
}
}
object SmartBuilderOps
{
def <<= [A](f: BuildStep[Throwable, A]) = f match {
case Continue(v) => v
case Failure(e) => e
}
implicit val applicative = applicativeBuilder[Throwable]
implicit def build[A,B](s: BuildStep[Throwable,A => B])=new SmartBuilder(s)
implicit def smartify[A,B,C](target: Curryable[A,B,C])(implicit applicative: Applicative[({type f[x] = BuildStep[Throwable, x]})#f]) = build(applicative.unit(target.curried))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment