6

I have a method that is able to persist any type, as long as that type has a io.circe.Encoder[A] instance, something like this:

def persist[A](a: A)(implicit ea: Encoder[A]): Boolean

Now while testing this, I can create any old case class, or set of case classes under a sealed trait, creating an ADT, and use automatic typeclass derivation to create the Encoder, and also to create the ScalaCheck Arbitrary instance, making this very nice to test.

Is it possible perhaps to use Shapeless in some way to create arbitrary families of case classes (and therefore automatically derive Encoder and Arbitrary instances) so that I can be sure my persist method works with any type?

I have no idea where to even start with this one, let alone try and describe a type for this.

Noel M
  • 15,812
  • 8
  • 39
  • 47

0 Answers0