scalacheck-shapeless
scalacheck-shapeless copied to clipboard
Summon a generated instance without making it implicit
I have a case class with a lot of members that yields well to generating an Arbitrary
instance using scalacheck-shapeless, but some individual field values I'd like to discard as invalid.
For that purpose, I wanted to generate the instance using this library, call filter
on it and make the result of that implicit
.
I couldn't find anything in the documentation explaining how to generate an instance without making it implicit.
After some trial and error, I came up with:
implicit val arbitraryFoo: Arbitrary[Foo] = {
val baseArbitrary = implicitly[Strict[MkArbitrary[Foo]]].value.arbitrary.arbitrary
baseArbitrary.filter(validationCheck)
}
Is there a better way I'm missing?
If yes, it should be added to the documentation.
If not, this seems useful and can be implemented (see semiauto
generic derivation in Circe as an example).