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 imap and iemap to Codec #1438

Merged
merged 2 commits into from May 7, 2020

Conversation

ybasket
Copy link
Contributor

@ybasket ybasket commented Apr 9, 2020

Adding an instance of cats.Invariant gives access to imap, further iemap is added on Codec itself for cases where "decoding" can fail. Handy for AnyVals and similar wrapper types.

Adding an instance of cats.Invariant gives access to `imap`, further `iemap` is added on Codec itself for cases where "decoding" can fail.
@travisbrown
Copy link
Member

Sorry for the long delay in responding. I've been reluctant to add something like this, because it felt like a dangerous step down a slippery slope toward thinking of Codec as a type class, and not just a thing that makes defining Encoder and Decoder instances a little more convenient.

I've been thinking about it a little more, though, and I'm not sure it's that big a deal. I'm inclined to go ahead and merge this.

@ybasket
Copy link
Contributor Author

ybasket commented Apr 17, 2020

No problem. I know you're busy working on awesome stuff like dhallj, so I'm fine waiting :)

I definitely see your point and wouldn't be disappointed if the PR is declined for that - these methods can be useful in some cases, but it's also limited as you often don't have a "base" Codec at hand, so you don't get to use imap.

There's some prior art in doobie, Meta is similar to Codec (with differences, for example it has primitive instances itself) and has imap: https://github.com/tpolecat/doobie/blob/master/modules/core/src/main/scala/doobie/util/meta/meta.scala

@travisbrown travisbrown merged commit 009e0c4 into circe:master May 7, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants