Is it possible to automatically derive a sealed trait family/ADT?
Asked Answered
S

0

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.

Sailfish answered 20/4, 2016 at 13:52 Comment(3)
Parametricity says that this shouldn't be necessary, but in practice I agree that it would be kind of handy sometimes.Dorran
github.com/alexarchambault/scalacheck-shapeless/issues/1 yup, I'd like that.Cham
It's on my TODO list.Buiron

© 2022 - 2024 — McMap. All rights reserved.