root package
package root
Package Members
- package scodec
Combinator library for working with binary data.
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
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