Last active
August 29, 2015 14:23
-
-
Save Alefas/32cf7f35f97e14800544 to your computer and use it in GitHub Desktop.
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
class A[T] | |
class C[T] | |
object Apply { | |
trait ApplyMagnet { | |
type R | |
def apply(): R | |
} | |
object ApplyMagnet { | |
implicit def aMagnet[T](a: A[T]): ApplyMagnet {type R = String} = new ApplyMagnet { | |
override type R = String | |
override def apply(): R = { | |
"A is applied" | |
} | |
} | |
implicit def cMagnet[T](a: C[T]): ApplyMagnet {type R = String} = new ApplyMagnet { | |
override type R = String | |
override def apply(): R = { | |
"C is applied" | |
} | |
} | |
} | |
def apply(magnet: ApplyMagnet): magnet.R = magnet.apply() | |
} | |
Apply(new A[String]) | |
Apply(new C[String]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment