Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summon a generated instance without making it implicit #114

Open
koterpillar opened this issue Jul 16, 2019 · 0 comments
Open

Summon a generated instance without making it implicit #114

koterpillar opened this issue Jul 16, 2019 · 0 comments

Comments

@koterpillar
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant