Skip to content

Instantly share code, notes, and snippets.

@ahoy-jon
Created November 15, 2012 17:25
Show Gist options
  • Save ahoy-jon/4079924 to your computer and use it in GitHub Desktop.
Save ahoy-jon/4079924 to your computer and use it in GitHub Desktop.
implicit !
case class ImplicitInject[I,B,C](f: (I,B) => C) {
def apply(b:B)(implicit i:I):C = f(i,b)
//def i(b:B)(implicit i:I):C = f(i,b) // it could be "explicit"
}
object ImplicitInject {
implicit val a:Int = 1
implicit def toImplicitInject[A,B,C](f:(A,B) => C) = ImplicitInject(f)
}
object ImplicitInjectApp extends App {
import ImplicitInject._
val f = (_:Int) + (_:Int)
println(f(2) == f(1,2)) //true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment