Skip to content

Instantly share code, notes, and snippets.

@monadplus
Created April 6, 2019 16:59
Show Gist options
  • Save monadplus/6e474b6f247ba17150b3a935b72f3373 to your computer and use it in GitHub Desktop.
Save monadplus/6e474b6f247ba17150b3a935b72f3373 to your computer and use it in GitHub Desktop.
Type class constraint in extension classes.
trait Ops[A] {
def typeClassInstance: Show[A]
def self: A
def show: String = typeClassInstance.show(self)
}
trait ToShowOps {
implicit def toShow[A](target: A)(implicit tc: Show[A]): Ops[A] = new Ops[A] {
val self = target
val typeClassInstance = tc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment