Skip to content

Instantly share code, notes, and snippets.

@Alefas
Last active August 29, 2015 14:23
Show Gist options
  • Save Alefas/32cf7f35f97e14800544 to your computer and use it in GitHub Desktop.
Save Alefas/32cf7f35f97e14800544 to your computer and use it in GitHub Desktop.
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