Created
January 24, 2018 22:42
-
-
Save nrinaudo/7171954254d3743c004762f03e54813f to your computer and use it in GitHub Desktop.
Semi-automatic derivation
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
import io.circe._ | |
import io.circe.generic.semiauto._ | |
import org.scalacheck._, derive._ | |
sealed trait Or[+A, +B] extends Product with Serializable | |
final case class Left[A](a: A) extends Or[A, Nothing] | |
final case class Right[B](b: B) extends Or[Nothing, B] | |
object Or { | |
// Compiles | |
implicit def decoder[A: Decoder, B: Decoder]: Decoder[A Or B] = deriveDecoder | |
// Does not compile | |
implicit def cogen[A: Cogen, B: Cogen]: Cogen[A Or B] = MkCogen[A Or B].cogen | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What I can't really work out yet is how circe manages this behaviour:
How does it know to derive instances for
Left[Int]
andRight[Boolean]
, but notFoobar
?!