The Decoder class is the base type to implement custom decoders.
It has three type parameters:
In for input. The input to a decoder can be any raw value that your decoder
can extract information from. In a simple case it could be a string value
or an array of bytes. If decoders are chained, the input needs to be
transferred from one decoder to the following one. That is why
DecodeResult has an Input as well. It is important to notice that
what is passed to the next decoder needs to be the relative input and not the
original one. For efficiency reasons, most decoders will wrap their own input
into some more sophisticated type to allow tracking the current position in
the stream.
Out for output. It's the type of the value return by the decoder if it
succeeds. Through operations like Decoder.map and
Decoder.flatMap, this type can be changed.
Err for error. It's the type of the error message. In some
implementations it might be as simple as string. For the embedded decoders
(text and value), the error is fixed to the
DecodeError unione type.
The constructors for DecodeError have more semantic value than
strings and can be properly used for localization.
Given a separator decoder, it returns an array of values from the current
decoder. It is expected that at least times values are returned from this
decoder.
Given a separator decoder, it returns an array of values from the current
decoder. It is expected that at most times values are returned from this
decoder.
Similar to map but passes a tuple of res: Out and input: In. This is mostly useful when decoding
tokens to preserve the original position in the input.
Given a separator decoder, it returns an array of values from the current
decoder. It is expected that exactly times values are returned from this
decoder.
The Decoder class is the base type to implement custom decoders. It has three type parameters:
In
for input. The input to a decoder can be any raw value that your decoder can extract information from. In a simple case it could be astring
value or an array of bytes. If decoders are chained, the input needs to be transferred from one decoder to the following one. That is why DecodeResult has anInput
as well. It is important to notice that what is passed to the next decoder needs to be the relative input and not the original one. For efficiency reasons, most decoders will wrap their own input into some more sophisticated type to allow tracking the current position in the stream.Out
for output. It's the type of the value return by the decoder if it succeeds. Through operations like Decoder.map and Decoder.flatMap, this type can be changed.Err
for error. It's the type of the error message. In some implementations it might be as simple asstring
. For the embedded decoders (text and value), the error is fixed to the DecodeError unione type. The constructors for DecodeError have more semantic value than strings and can be properly used for localization.