The primary abstraction of this library is Codec, which provides the ability to encode/decode values to/from binary.
There are more general abstractions though, such as Encoder and Decoder. There's also GenCodec which extends
both Encoder and Decoder but allows the types to vary. Given these more general abstractions, a Codec[A] can be
represented as a GenCodec[A, A].
The more general abstractions are important because they allow operations on codecs that would not otherwise be possible.
For example, given a Codec[A], mapping a function A => B over the codec yields a GenCodec[A, B]. Without the
more general abstractions, map is impossible to define (e.g., how would codec.map(f).encode(b) be implemented?).
Given a GenCodec[A, B], the encoding functionality can be ignored by treating it as a Decoder[B], or the encoding
type can be changed via contramap. If after further transformations, the two types to GenCodec are equal, we can
reconstitute a Codec from the GenCodec by calling fuse.
See the codecs package object for pre-defined codecs for many common data types and combinators for building larger
codecs out of smaller ones.
Combinator library for working with binary data.
The primary abstraction of this library is Codec, which provides the ability to encode/decode values to/from binary.
There are more general abstractions though, such as Encoder and Decoder. There's also GenCodec which extends both
Encoder
andDecoder
but allows the types to vary. Given these more general abstractions, aCodec[A]
can be represented as aGenCodec[A, A]
.The more general abstractions are important because they allow operations on codecs that would not otherwise be possible. For example, given a
Codec[A]
, mapping a functionA => B
over the codec yields aGenCodec[A, B]
. Without the more general abstractions,map
is impossible to define (e.g., how wouldcodec.map(f).encode(b)
be implemented?). Given aGenCodec[A, B]
, the encoding functionality can be ignored by treating it as aDecoder[B]
, or the encoding type can be changed viacontramap
. If after further transformations, the two types toGenCodec
are equal, we can reconstitute aCodec
from theGenCodec
by callingfuse
.See the codecs package object for pre-defined codecs for many common data types and combinators for building larger codecs out of smaller ones.
For the categorically minded, note the following:
Decoder
is a monadEncoder
is a contravariant functorGenCodec
is a profunctorCodec
is an invariant functor