Created
April 6, 2019 16:59
-
-
Save monadplus/6e474b6f247ba17150b3a935b72f3373 to your computer and use it in GitHub Desktop.
Type class constraint in extension classes.
This file contains hidden or 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
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