Derive unwrapped Codec for newtypes
Closed this issue · 2 comments
It would be a small, but a nice feature to have vulcan automatically derive "unwrapped" codecs for value classes, similarly to what circe provides via the eneric-extras module, e.g.
final case class EventId(value: String)
Instead of
Codec[String].imap(EventId.apply)(_.value)
we could just write the following to get the codec automatically derived:
Codec.deriveUnwrapped[EventId]
It's slightly shorter and easier to write if you use the generic module.
What do you think?
Codec.derive
already has this behaviour for value classes (extends AnyVal
). I’m not sure it’s worth having a separate construct for the non-value class case to shave off a few characters (plus the increase in compile time).
Is there something I’m missing here?
Oh, I didn't realise it was already supported when using AnyVal
- that's great! Thanks for clarifying this, it might be worth mentioning about it in the docs. I'll open a small PR when I get a chance.