Skip to content

Instantly share code, notes, and snippets.

@stevebakh
Created March 20, 2018 16:23
Show Gist options
  • Select an option

  • Save stevebakh/7f39fd752780ef7a12a724da2fdc98f5 to your computer and use it in GitHub Desktop.

Select an option

Save stevebakh/7f39fd752780ef7a12a724da2fdc98f5 to your computer and use it in GitHub Desktop.
Just playing around with context bounds and implicit type classes. Shows the two forms that can be used to access the implicit typeclass.
trait A {
val name = "Aaaaay"
}
class B extends A
trait C[T <: A] {
def gofuckyourself(t: T): String
}
implicit val typeclass: C[B] = new C[B] {
override def gofuckyourself(t: B) = t.name + ", go fuck yourself!"
}
def foo[T <: A : C](input: T): Unit = {
println(implicitly[C[T]].gofuckyourself(input))
}
def bar[T <: A](input: T)(implicit ev: C[T]): Unit = {
println(ev.gofuckyourself(input))
}
foo(new B())
bar(new B())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment