-
-
Save afsalthaj/b658245bf47f647f02513213ce6aa719 to your computer and use it in GitHub Desktop.
This file contains 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
// Write Json. In this case the type parameters in the type class | |
// came at the method parameters level (contra variant position), calling for having | |
// a `Contramap` | |
trait EncodeJson[A] { self => | |
def toJson(a: A): Json | |
def contramap(f: B => A): EncodeJson[B] = new EncodeJson[B] { | |
def toJson(a: B): Json = self.toJson(f(b)) | |
} | |
} // Implies EncodeJson can have an instance of contravariant functor | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment