A simple encapsulation of an Encoder and Decoder for the same type, as one entity.
Sometimes it's easier to supply just a single implicit for a type, rather than two. As an alternative to writing a separate Encoder and Decoder for type A you can also write a Codec for A. (Encoder and Decoder can be implicitly "unpacked" from a codec.)
However, in order to not hinder composability Codecs should only ever be supplied, never consumed.
So, if you write an encoder, decoder or codec for a generic type, which itself requires implicitly
available encoders and/or decoders for certain type parameters (like Encoder.forOption
, for example)
then you should never require implicitly available Codecs, but rather Encoders and Decoders separately.
- Companion:
- object
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any