Codec

final case class Codec[A](encoder: Encoder[A], decoder: Decoder[A])

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

Value members

Concrete methods

@inline
def bimap[B](f: B => A, g: A => B): Codec[B]
def withDecoder(decoder: Decoder[A]): Codec[A]
def withEncoder(encoder: Encoder[A]): Codec[A]

Inherited methods

def productElementNames: Iterator[String]
Inherited from:
Product
def productIterator: Iterator[Any]
Inherited from:
Product