Skip to content

Instantly share code, notes, and snippets.

@Haaroon
Created January 18, 2022 18:11
Show Gist options
  • Save Haaroon/ef6699a32f8a8423eb954c4ffed512ac to your computer and use it in GitHub Desktop.
Save Haaroon/ef6699a32f8a8423eb954c4ffed512ac to your computer and use it in GitHub Desktop.
type gist
sealed trait Callable[T] {
def call(): T
}
object Caller {
def call[C, A <: Callable[C]](callable: A): C = {
callable.call()
}
}
case class Duck(name: String) extends Callable[String] {
def call(): String = {
"quack"
}
}
val duck = Duck("Donald")
println(Caller.call[String, Duck](duck))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment