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

Add a function similar to Gen.resultOf to Cogen #589

Closed
nigredo-tori opened this issue Dec 12, 2019 · 1 comment
Closed

Add a function similar to Gen.resultOf to Cogen #589

nigredo-tori opened this issue Dec 12, 2019 · 1 comment
Milestone

Comments

@nigredo-tori
Copy link
Contributor

Currently to build a Cogen for some type (A) that is isomorphic to another type (B) for which a Cogen exists, we need to summon the Cogen[B], and contramap it. This leads to noisy code like this:

implicit val InstantCogen: Cogen[Instant] =
  Cogen[(Long, Int)].contramap(i => (i.getEpochSecond, i.getNano))

It should be easy to add Cogen.resultOf that would derive a Cogen[A] given a function A => B (and the implicit Cogen[B] in scope), similarly to what Gen.resultOf does. We would then be able to write:

implicit val InstantCogen: Cogen[Instant] =
  Cogen.resultOf(i => (i.getEpochSecond, i.getNano))
@nigredo-tori nigredo-tori changed the title Add Cogen.resultOf Add a function similar to Gen.resultOf to Cogen Dec 12, 2019
@ashawley ashawley added this to the 1.15.0 milestone Dec 13, 2019
@non
Copy link
Contributor

non commented May 7, 2020

We merged #590 to master. Thanks! Closing.

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

3 participants